Created
May 15, 2015 16:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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