• Hi,

    in my child theme’s functions.php I tried to apply a filter to hide certain posts that belong to a travel guide I’m working on, I tried to use this code here:

    function excludeMetaKey($query) {
    
      if ( $query->is_home && $query->is_feed && $query->is_main_query() ) {
    
          $query->set('meta_key=mappress&meta_value=ns');
       }
    return $query;
    }
    
    add_filter('pre_get_posts', 'excludeMetaKey');

    Unfortunately it is not working. I stumbled over your plugin and wonder if it is already doing at least a part of my requirements? Maybe you can extend your plugin to support posts as well? I like to hide certain posts as said from being displayed ad my feeds and main loop. They should still be available by search or category listings.

    Many thanks in advance.
    Cheers
    Yogie

    https://wordpress.org/plugins/im8-exclude-pages/

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

    (@intermedi8)

    Hi,
    if you want to hide some posts, why dont you use the draft-status?
    Or you could use a simple query which excludes the posts with a certain category and/or tag.
    Using a filter seems unnecessary complex in this case?!

    Our plugin is only for hiding pages in automatic wordpress list functions (for example when used for building menus). Its not meant to filter posts, as this is a totally different use case which could easily achieved with wordpress core functions.

    Thread Starter YogieAnamCara

    (@yogieanamcara)

    Thanks for your quick reply!

    The draft status will not work as the posts should be readable, searchable and displayed when you are looking for posts of the categories the post belongs to.

    My posts do have often multiple categories, so looking for an option to hide posts with certain categories will not work.

    The easiest way for me to identify is a custom field (meta_key) in a post.

    Thanks again for your feedback!

    Plugin Author intermedi8

    (@intermedi8)

    What you want could easily achieved with a meta_query or meta_compare.

    For example:
    query_posts(array('post_type' => 'post', 'meta_key' => 'YOUR_META_KEY', 'meta_compare' => '==', 'meta_value' => 'YOUR_META_VALUE'));

    Or:

    'meta_query' => array(
        array(
            'key' => 'YOUR_META_KEY',
            'value' => 'YOUR_META_VALUE',
            'compare' => 'LIKE',
        ),
    )

    Thread Starter YogieAnamCara

    (@yogieanamcara)

    Mhmh,

    seems not to work if I add it to my filter.

    Anyways thank you for trying to help!

    Cheers
    Yogie

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘question and maybe feature wish’ is closed to new replies.