• Hi, I have an Archive page and I put a Search form on that page. When navigating the archive, let’s say you’re an Page 3 (/page/3/), the Search form is still there but when you make a search, the results page is showing on the third page too! (/page/3/) That’s because you were on Page 3 when you made the search. Is it how the Search is supposed to work? How can I make sure the search results show on the first page and not on the X page I was on when I used the form?

    Thanks for your help! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • No, it should start on page 1.
    It could be because you’re using relative urls on form action.
    Do you have a link to take a look?

    Thread Starter Alkorr

    (@alkorr)

    Hi David, thank you for your reply. Unfortunately my blog is offline for now but it was a problem I also encountered with my previous theme…

    I have another problem (but surely related) when I’m on the 404 page (www.mywebsite.com/bookz/ instead of https://www.mywebsite.com/books/). When I do a search for Hemingway from this 404 error page, despite of showing all the results for Hemingway (there are plenty!) it returns ‘0 post found’ and the URL is https://www.mywebsite.com/bookz/?s=Hemingway instead of https://www.mywebsite.com/?s=Hemingway…

    I know you’re kind of blind here but what do you think it could be? I searched on Google and the WP Forums and couldn’t find anything :\

    In case it helps, here is my search box:

    <form role="form" id="searchform" method="get" action="<?php home_url(); ?>">
    <div class="input-group">
    <input type="text" name="s" id="s" class="form-control" placeholder="Search..." >
    <span class="input-group-addon">
    <button type="submit">
    <span class="glyphicon glyphicon-search"></span>
    </button>  
    </span>
    </div>
    </form>

    Thank you for your help! ??

    Thread Starter Alkorr

    (@alkorr)

    I replaced:

    <?php home_url(); ?>

    by:

    <?php echo esc_url( home_url( '/' ) ); ?>

    Now my Search from the 404 Page works fine, but the Search I used to make from the Books category (/books/) is now made from the whole website but I want it to still be only from the the Books category.

    I think it should have something to do with getting the current_page_url() but it doesn’t work when I add this parameter :\

    Any idea? I’m doing my best to find the solution by myself, I’m trying but a little help is always welcome! ??

    Is books a custom post type?

    What if you add this hidden input to your form:

    <input type="hidden" name="post_type" value="books" />

    Thread Starter Alkorr

    (@alkorr)

    Hi David, nope, it’s not a Post Type per se, it’s a Category. And since the Search box is in my Archive.php page, the ‘value’ should be dynamic to search in the Books category when showing the Books archive posts, same for Movies, etc…

    Thank you for you help ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search Form in Archives.php’ is closed to new replies.