Skip to content

Instantly share code, notes, and snippets.

@randgroupmrkt
Last active July 21, 2016 15:45
Show Gist options
  • Select an option

  • Save randgroupmrkt/25a90d409f0e84b48176dba798213428 to your computer and use it in GitHub Desktop.

Select an option

Save randgroupmrkt/25a90d409f0e84b48176dba798213428 to your computer and use it in GitHub Desktop.
Hide password protected posts
//////////////////
// Add to functions.php
/////////////////


// Filter to hide protected posts
function exclude_protected($where) {
	global $wpdb;
	return $where .= " AND {$wpdb->posts}.post_password = '' ";
}

// Decide where to display them
function exclude_protected_action_x($query) {
	if (!is_single() && !is_page() && !is_admin()) {
		add_filter('posts_where', 'exclude_protected');
	}
}

// Action to queue the filter at the right time
add_action('pre_get_posts', 'exclude_protected_action');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment