Skip to content

Instantly share code, notes, and snippets.

@sethshoultes
Created May 15, 2015 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sethshoultes/24d5540575920e5fd7eb to your computer and use it in GitHub Desktop.
Save sethshoultes/24d5540575920e5fd7eb to your computer and use it in GitHub Desktop.
Exclude password protected events and posts from the WordPress loop. Adapted from Stackoverflow: http://stackoverflow.com/questions/7538959/how-to-exclude-password-protected-posts-in-wordpress-loop
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
// Create a new filtering function that will add our where clause to the query
function ee_password_post_filter( $where = '' ) {
// Make sure this only applies to loops / feeds on the frontend
if (!is_single() && !is_admin()) {
// exclude password protected
$where .= " AND post_password = ''";
}
return $where;
}
add_filter( 'posts_where', 'ee_password_post_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment