Support » Plugin: Simply Hide Pages » [Plugin: Simply Hide Pages] Feature request

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author julienvdg

    (@julienvdg)

    Thanks !

    Yes it was not designed to hide pages from the searches. I’ll have to look if it’s easy to do… If it is I’ll do a new version 😉

    I managed it by adding the following to functions.php, but would go better in a plugin (but really WP should have Visibility: public, password, private & hidden.

    /*
     * from brickbrigade's code at http://wordpress.org/support/topic/get_post-query-where-posts-dont-have-a-specific-meta_key-1
     */
    add_filter('query_vars', 'metakey_queryvars' );
    function metakey_queryvars( $qvars )
    {
      $qvars[] = 'not_meta_key';
      return $qvars;
    }
    
    add_filter('posts_where', 'metakey_where' );
    function metakey_where( $where )
    {
        global $wp_query;
        global $wpdb;
    
        if( isset( $wp_query->query_vars['not_meta_key'] )) {
           $where .= $wpdb->prepare(" AND $wpdb->posts.ID NOT IN ( SELECT post_id FROM $wpdb->postmeta WHERE ($wpdb->postmeta.post_id = $wpdb->posts.ID) AND meta_key = %s) ", $wp_query->query_vars['not_meta_key']);
        }
        return $where;
    }
    
    /*
     * variation of jamesstiff's code at http://wordpress.org/support/topic/excluding-pages-from-search-results
     */
    function mySearchFilter($query) {
    if ($query->is_search) {
    $query->set('not_meta_key', 'hide');
    }
    return $query;
    }
    add_filter('pre_get_posts','mySearchFilter');
    Plugin Author julienvdg

    (@julienvdg)

    Thanks for the code !

    In the mean time I found the following plugin (untested though) :
    simply-exclude

    I might improve simply-hide-page to also hide from search later…

    Simply-Exclude looks good but for pages it appears to only exclude them from searches. And with 2084 lines of code, it is slightly longer than your plugin 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Simply Hide Pages] Feature request’ is closed to new replies.