[Resolved] How to exclude GP searching pages

Home Forums Support [Resolved] How to exclude GP searching pages

Home Forums Support How to exclude GP searching pages

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1132667
    Nacho

    Hello,

    How would you exclude the GP search funcionanility from searching pages?

    Thanks a lot.

    #1133118
    Leo
    Staff
    Customer Support

    Hi there,

    We will need this filter:
    https://docs.generatepress.com/article/generate_navigation_search_output/

    Do you only want to search for posts?

    Let me know 🙂

    #1133146
    Nacho

    Hi Leo,

    Yes I just want to search for posts not pages.

    Thanks!

    #1133260
    Leo
    Staff
    Customer Support

    Try this PHP snippet:

    add_filter( 'generate_navigation_search_output', function() {
        printf(  
            '<form method="get" class="search-form navigation-search" action="%1$s">
                <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
                <input type="hidden" name="post_type" value="post" />
            </form>', 
            esc_url( home_url( '/' ) ), 
            esc_attr( get_search_query() ),   
            esc_attr_x( 'Search', 'label', 'generatepress' ) 
        ); 
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1133356
    Nacho

    Hello Leo,

    I´ve just put the code but it´s not working.

    I´ve tried in the live version so I´ve updated this post website URL.

    If you search for example the word “tour” it will show the tour page and that´s a page not a post.

    Thanks a lot.

    #1133382
    Leo
    Staff
    Customer Support

    I’m not seeing the navigation search in the URL provided.

    Can you double check?

    Let me know 🙂

    #1133775
    Nacho

    Hello Leo,

    I´ve just updated the url so you can see the search box.

    Thanks a lot.

    #1134359
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    It doesn’t look like you’re using the Navigation Search.

    Are you wanting to target the search bar in your right sidebar?

    #1134378
    Nacho

    Hi Tom,

    Oh yes the search bar in the sidebar. Actually I thought it was the same.

    What should I do?

    Thanks a lot.

    #1134498
    Leo
    Staff
    Customer Support

    That’s a WordPress search widget which is different than GP’s navigation search:
    https://www.wpbeginner.com/wp-tutorials/how-to-exclude-pages-from-wordpress-search-results/

    #1134743
    Nacho

    Hi Leo,

    Understood. That worked like charm.

    Thanks a lot for the help to all of you and have a good day.

    #1135010
    Leo
    Staff
    Customer Support

    No problem 🙂

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