Support » Fixing WordPress » Pagination and Custom Search page

  • Hello all,

    I am stuck on an issue since two days. I am not an expert, but with what I was doing so it was quite expected that I will get in trouble. So, I am.

    I have 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 appear 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 “” – 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 have print_r($wp_query) which can help understand the issue”

    I am stuck on this since two days. Have tried several several code blocks from support forums, stack exchange, and other blogs.

    Any help will be heartily appreciated.

  • The topic ‘Pagination and Custom Search page’ is closed to new replies.