• Resolved ilfedevisio

    (@ilfedevisio)


    Hi, I’m coding my own theme for wordpress but I have a problem with the search widget: when I enter the keys I want to search and click on “search”, the url of the page changes, adding to the homepage url a “/?s=” followed by the terms I searched for, but the page shows all the posts instead of showing only the interested ones.
    I wrote a searchform.php for the style:

    <form role="search" method="get" class="" action="<?php echo esc_url(home_url('/')); ?>">
        <div class="input-group">
            <input type="search" class="form-control" placeholder="Search" value="<?php echo get_search_query(); ?>" name="s" title="Search">
        </div>
    </form>

    and added the theme support for html5.
    It’s ok for me to load the index.php atm, so I didn’t write a search.php file.
    What am I doing wrong? If I change the theme to twentynineteen everything’s fine… but I can’t find differences between these 2 themes in the files.
    Hope someone can help me

Viewing 4 replies - 1 through 4 (of 4 total)
  • Your searchform looks fine. The theme support for html5 only affects the built-in searchform so having both is strange.
    Since you don’t have a search.php, the index.php is used, but that shouldn’t affect which results are shown.
    What exactly is wrong?

    Thread Starter ilfedevisio

    (@ilfedevisio)

    Whene I type some keywords inside the search form and press enter, the page still shows me all the posts, without filtering them by the keywords.
    For example, if I search for “Sunrise” and I have 3 blog posts named “Sunrise”, “River” and “Cakes”, the result isn’t the only post sunrise, but all these posts.
    The form isn’t filtering data. But, the url adds in the end /?s=sunrise, like in other themes

    • This reply was modified 6 years, 4 months ago by ilfedevisio.

    You can try a search from the URL only, not the search widget, to rule out the searchform itself. If it does not show the correct results, the problem is in your theme, where you have a filter or some code affecting the main query. Themes should not affect the main query.

    Thread Starter ilfedevisio

    (@ilfedevisio)

    The problem was on the loop; I added a new WP_Query with all posts and that was the problem. Thanks for helping me, have a nice day!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Search widget not filtering posts’ is closed to new replies.