Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Display search result in my theme's search.php template
This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko 6 years, 12 months ago.
- AuthorPosts
- April 29, 2017 at 11:11 am #12914
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 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(); ?>
- This topic was modified 6 years, 12 months ago by Ernest Marcinko. Reason: PHP code fix
- This topic was modified 6 years, 12 months ago by Ernest Marcinko.
May 1, 2017 at 9:29 am #12930Hi,
I think there might be actually two possible causes:
1. Make sure that the search override is enabled: https://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:
$the_query = new WP_Query( $args );
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:
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 1, 2017 at 10:38 am #12934You cannot access this content.May 1, 2017 at 10:48 am #12935You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
The topic ‘Display search result in my theme's search.php template’ is closed to new replies.