I am stuck on an issue for the last two days. I have a CPT - 'listings'. This is it's archive page
Till here, everything is fine.
I put in a search form there, and added this to
pre_get_posts
:if ($query->is_main_query() && $query->is_post_type_archive('listings') && !is_admin() && is_search()) { echo '<br/>me runnning<br/>'; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $query->set('paged', $paged); $query->set('posts_per_page', 1);
Another code in 'functions.php' that redirects my search to 'archive_listings.php', which is the same archive page for 'listings' CPT
When I do a search the results that appears are fine.
Problem arises when I try to get on the second page in the search results.
- When I click on next page for search results, it takes me to the
wwwsitename.com/listings/page/2
which is the page of archive-listings default results.
- In other words, when I try to move to next page - the query forgets about the search terms, and get the second page of default archive for listings.
I am not sure, if I was able to clearly explain it. So, I haveprint_r($wp_query)
which can help understand the issue
I have tried several code blocks from support forums, stack exchange, and other blogs.
Any suggestions will be heartily appreciated.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $query->set('paged', $paged);
from yourpre_get_posts
function