This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Display search result in my theme's search.php template

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Display search result in my theme's search.php template

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12914
    username94838username94838
    Participant

    Your plugin works great for my small vacantion rental website however I would like to use my theme’s result page when I display the results. While the ajax version works as It should, all the filters work, when I choose to display the results on another page, the filters don’t work anymore, I get returned all the results, not the filtered ones. This is the search.php template I am using. I guess the search parameters are wrong. Can you tell me what’s wrong with it? .

    [php]<?php get_header(); ?>
    <?php
    $s=get_search_query();
    $args = array(
    ‘s’ =>$s
    );
    // The Query
    $the_query = new WP_Query( $args );
    if ( $the_query->have_posts() ) {
    _e("<h2 style=’font-weight:bold;color:#000’>Search Results for: ".get_query_var(‘s’)."</h2>");
    while ( $the_query->have_posts() ) {
    $the_query->the_post();
    ?>
    <li>
    <a>"><?php the_title(); ?></a>
    </li>
    <?php
    }
    }else{
    ?>
    <h2 style=’font-weight:bold;color:#000’>Nothing Found</h2>
    <div class="alert alert-info">
    <p>Sorry, but nothing matched your search criteria. Please try again with some different keywords.</p>
    </div>
    <?php } ?>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>[/php]

    • This topic was modified 9 years, 1 month ago by Ernest MarcinkoErnest Marcinko. Reason: PHP code fix
    • This topic was modified 9 years, 1 month ago by Ernest MarcinkoErnest Marcinko.
    #12930
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    I think there might be actually two possible causes:

    1. Make sure that the search override is enabled: http://i.imgur.com/viRLn6S.png
    In this case however I don’t think that is going to solve the issue by itself.

    2. The issue with the code is that there is a duplicate query executed, which cannot be overridden by ajax search pro, on this line:

    [php]$the_query = new WP_Query( $args );[/php]

    This is not neccessary, as when the execution gets to search.php file, the search results are already parsed, no need to query again.
    Simply the have_posts() and the_posts() calls should be made, without the query object.

    I’ve made a correction to your code, but I have not tested it, please be careful. This is what it should look like:

    #12934
    username94838username94838
    Participant

    You cannot access this content.

    #12935
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Display search result in my theme's search.php template’ is closed to new replies.