[Resolved] How to display only post in search results?

Home Forums Support How to display only post in search results?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #366844
    Fernando

    Hello

    I use WordPress download manager and it create a page for each file, I don’t use these pages, I attach the files to posts that’s Why i don’t want to display in search.

    In function.php i use this code.

    function fb_search_filter( $query ) {
        if ( ! $query->is_admin && $query->is_search ) {
            $query->set( 'post_type', array( 'downloads', 'post' ) );
        }
    
        return $query;
    }
    add_filter( 'pre_get_posts', 'fb_search_filter' );

    Is this correct? or is better in another way?

    Thanks

    GeneratePress 1.4
    GP Premium 1.4.2
    #366987
    Tom
    Lead Developer
    Lead Developer

    That’s exactly how I would do it 🙂

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.