• Resolved 4briang

    (@4briang)


    Thanks for a great plugin! Wondering if it’s possible to create a filter based on ‘acfbs_search_is_available’ to exclude all posts from a certain author? Something like:

    function wp_search_filter( $query ) {
      if ( $query->is_search && !is_admin() )
        $query->set( 'author','-35' );
      return $query;
    }
    add_filter( 'pre_get_posts', 'wp_search_filter' );

    • This topic was modified 3 years, 2 months ago by 4briang.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @4briang,

    Thank you for your message.

    You don’t need to use the acfbs_search_is_available filter to do what you want to do. Just use the code you provided below and it should work without a problem.

    Best,
    Mateusz

    Thread Starter 4briang

    (@4briang)

    Wow, thanks for the quick answer. That isn’t working for me but this one is so I’m covered. Thanks again.

    add_filter( 'pre_get_posts', 'exclude_pages_search_when_logged_in' );
    function exclude_pages_search_when_logged_in($query) {
        if ( $query->is_search && is_user_logged_in() )
            $query->set( 'post__not_in', array( 11, 22, 33, 44, 55 ) ); 
     
        return $query;
    }
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @4briang This issue has nothing to do with my plugin. My plugin plugs into the WordPress search engine, so all WordPress hooks should work without problems.

    In your function you declare that I would like to exclude posts when logged in search. What exactly would you like to achieve?

    Thread Starter 4briang

    (@4briang)

    @mateuszgbiorczyk Thanks for the reply. I didn’t say anything was broken with your plugin. I’m sure there’s another reason the author filter wasn’t working. I actually want to hide specific posts if a user is not logged in. So that was simple enough with a quick change to the filter. You can close this thread for my purposes although I appreciate you making sure I’m set.

    // remove posts from search if user is not logged in
    
    add_filter( 'pre_get_posts', 'exclude_pages_search' );
    function exclude_pages_search($query) {
        if ( $query->is_search && !is_user_logged_in() )
            $query->set( 'post__not_in', array( 11, 22, 33, 44, 55 ) ); 
        return $query;
    }
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Exclude posts from an author’ is closed to new replies.