Forums › Forums › Search & Filter Pro › Weird Pagination issue when Search and Filter Pro plugin is active
- This topic has 5 replies, 2 voices, and was last updated 4 years, 8 months ago by
Trevor.
-
Anonymous(Private) August 20, 2020 at 4:09 pm #256776
I love the plugin and does everything I was looking for. But the problem I am facing is that when I am trying to display all custom post types of a author through author.php, the pagination does not working. It is so weird, it would display the all the posts of a author and page numbers are being displayed but when I click on the page 2 or 3 and so on I am getting a not found page.
But If I deactivate the search and filter pro, them everything works fine. I am using wp-pagenavi for my theme pagination. The theme I am using is called ENFOLD.
Any idea what would be causing this. Below is my wp_query for getting all posts of a author
$args = array( 'post_type' => array( 'volunteer-position' ), 'post_status' => array( 'publish' ), 'author' => get_queried_object_id(), 'order' => 'ASC', 'orderby' => 'title', ); // query $custom_posts = new WP_Query( $args ); // the loop if ( $custom_posts->have_posts() ): while ( $custom_posts->have_posts() ) : $custom_posts->the_post(); // displaying the posts markup and content here endwhile; else: // nothing found endif; if (function_exists('wp_pagenavi')) { wp_pagenavi( array( 'query' => $custom_posts ) ); } // Restore original Post Data wp_reset_postdata();
Thank you and appreciate it
Trevor(Private) August 20, 2020 at 4:25 pm #256788You might try adding our filter to the arguments, like this:
$args = array( 'post_type' => array( 'volunteer-position' ), 'post_status' => array( 'publish' ), 'author' => get_queried_object_id(), 'order' => 'ASC', 'orderby' => 'title', 'search_filter_id' => 1234, );
Where you change 1234 for the ID number of your form.
Anonymous(Private) August 20, 2020 at 4:34 pm #256791Thanks for replying but I am not using the search and filter on the author page. Just trying to display the posts of a author when someone clicks on the author name.
There is something that is conflicting with search and filter plugin pagination or $query that is effecting other pages while displaying posts sir.
Anonymous(Private) August 20, 2020 at 4:59 pm #256798There is 100% something conflicting with $query, as when I added below to functions.php
function author_cpt_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_author()) { $query->set('post_type', array('volunteer-position')); $query->set('post_per_page', 6); } } } add_action('pre_get_posts','author_cpt_filter');
The pagination works 100% in author.php where search and filter is not being used. But where I am displaying the results using search and filter shortcode in a separate page, the results are being displayed but when I click on page 2, nothing happens and chrome debugger says the below
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://mysite.com/?sfid=3929&sf_action=get_data&sf_data=results&sf_paged=2
Thank you
Trevor(Private) August 21, 2020 at 10:58 am #256888Ah, using pre_get_posts will conflict with our plugin, as that WordPress function runs after our query is run. It should be possible to check which page you are on first (i.e. NOT the one S&F is on), by altering this line:
if ( !is_admin() && $query->is_main_query() ) {
If, for example, if search and filter is on your theme search results page, then checking is_search might do it:
if ( !is_admin() && $query->is_main_query() && (!is_search()) ) {
There are too many ways to check the page, so you will need to figure one that works for you.
-
AuthorPosts