Sometimes we use our WordPress “posts” for things like client proposals (ok, we should really be creating a custom-post-type for that, but we don’t always) which we password protect in order to keep the general public out of there. Of course, one of the problems with this is that a link to this Post/Proposal will appear in your “Recent Posts” feed. It’s easy to exclude these password-protected posts though, with just a little bit of code in the functions.php of your active child theme.

// Create a new filtering function that will add our where clause to the query
function my_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', 'my_password_post_filter' );

Quick…easy…worth the few extra lines of code, I think. Let me know if you’ve used this on any of your sites, or if you’ve accomplished the same thing another way.

thePixelPixie.com - WordPress boutique

Subscribe and receive my FREE eBook


4 MISTAKES You’re Making on Your Website that are Costing You MONEY!

  • This field is for validation purposes and should be left unchanged.

The Author

Save

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ready to chat about how ThePixelPixie can help?