The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Pagination and Custom Search page (1 post)

  1. Ankit Singla
    Posted 2 years ago #

    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: http://www.omaksolutions.com/clients/neetinpuri/localmag/listings

    - 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 "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 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.

Topic Closed

This topic has been closed to new replies.

About this Topic