• Gin

    (@rawdolphe)


    Hi, I am testing the Search template (as shipped) and there is a problem.

    1. When I set the Block Query Loop > Settings > to Inherit query from template (default setting) all is well; if I do a search it works as advertised – we see Posts and Pages…
    2. However, when I set the Block Query Loop > Settings > POST TYPE > to Posts = BIG PROBLEM; when I do a Search it outputs ALL the posts regardless of the keyword used for the search. BROKEN?
    3. Exact same problem as ‘2’ when set to Pages.

    Please advise, thank you.

    PS: I spotted another bug with the Search Block when in the menu, but will reserve it for another thread.

    • This topic was modified 3 months, 1 week ago by Gin.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Gin

    (@rawdolphe)

    Moderator jordesign

    (@jordesign)

    Thanks for doing that @rawdolphe – it looks like the best approach.

    Thread Starter Gin

    (@rawdolphe)

    Thanks @jordesign, I just added a reply there it seems that they are not fully understand what I was trying to explain originally 🙂

    Could you please check yourself if you have a minute, assuming you understood what the issue is? I attach a screenshot for reference.

    Thank you


    Moderator jordesign

    (@jordesign)

    Hi @rawdolphe – thanks for the additional information – seeing what you mean I understand a bit better now (and have also replied on Github).

    What you’re seeing is actually the expected behaviour. For the Query Loop block to show search results it will have to be set to ‘inherit query from template’ – as that is the query which contains the search results.

    As soon as you turn that off – you’re starting a brand new query (by selecting post/pages etc) and it won’t be picking up the search terms at all.

    Thread Starter Gin

    (@rawdolphe)

    Hi @jordesign, thanks for looking into this.

    So I have two simple questions:

    1. What is the Post / Page setting for then? The options are there but they don’t do anything for the search…
    2. How do we setup the Search to output Posts only, AND we the relevant keyword of course—as opposed to pulling ALL posts regardless of the chosen keyword? That should be simple enough I reckon.

    Is it a case were the Search pulls everything; Posts and Pages, and there are no other options and there is nothing we can do about it—appart from using a third party plugin?

    Further, something doesn’t add up to me because I saw some YouTube videos with 2023 and the Search was set to Post as described above, and it seemed to work fine, here is one: https://youtu.be/ilT_6dyVk10?feature=shared&t=315

    Thread Starter Gin

    (@rawdolphe)

    Update: in case the following could be useful to someone, insert it in your functions.php or use the Code Snippet plugin.

    // Modify WordPress search to only include posts
    function exclude_pages_from_search($query) {
        if ($query->is_search && !is_admin()) {
            $query->set('post_type', 'post');
        }
        return $query;
    }
    add_filter('pre_get_posts', 'exclude_pages_from_search');

    After adding this code snippet, the search results should only include posts, excluding pages.

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