Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Display search result in my theme's search.php template
- This topic has 3 replies, 2 voices, and was last updated 9 years, 1 month ago by
Ernest Marcinko.
-
AuthorPosts
-
April 29, 2017 at 11:11 am #12914
username94838
ParticipantYour 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 Marcinko. Reason: PHP code fix
-
This topic was modified 9 years, 1 month ago by
Ernest Marcinko.
May 1, 2017 at 9:29 am #12930Ernest Marcinko
KeymasterHi,
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:
May 1, 2017 at 10:38 am #12934username94838
ParticipantYou cannot access this content.
May 1, 2017 at 10:48 am #12935Ernest Marcinko
KeymasterYou cannot access this content.
-
This topic was modified 9 years, 1 month ago by
-
AuthorPosts
- The topic ‘Display search result in my theme's search.php template’ is closed to new replies.