Forums › Forums › Search & Filter Pro › Pagination not working for custom results
- This topic has 6 replies, 2 voices, and was last updated 5 years, 6 months ago by Trevor.
-
Anonymous(Private) May 24, 2019 at 5:44 am #212366
Hi there! I am setting up a search form to filter a custom post type that I am displaying using Beaver Builders posts module on this page: https://staging-universallifetools.kinsta.cloud/our-teachers
I am using a pre_get_posts to hook up the search and filter pro integration and the filtering itself works great, except the pagination is not working.
For example, when I go to https://staging-universallifetools.kinsta.cloud/our-teachers/?sf_paged=2 – it is still displaying page one of the results.
I am using the Custom display results method and have specified https://staging-universallifetools.kinsta.cloud/our-teachers as the template
Ajax container has been specified as #prac-grid-teacher and Ajax pagination is .fl-builder-pagination a
I am hoping you can point me in the direction of where I am going wrong.
Anonymous(Private) May 24, 2019 at 11:31 pm #212512Hi Trevor – I am using the below code. Happy to catchup via Skype but I am in Australia GMT +10 so not sure what time zone you are in?
add_filter(“pre_get_posts”, “modify_bb_query”);
function modify_bb_query($query){
if(!isset($query->query_vars[‘fl_builder_loop’])){
return $query;
}//if is page “our-teachers” and this is a
fl_builder_loop
if((is_page(“our-teachers”)) && ($query->query_vars[‘fl_builder_loop’] == true)){
//then attach S&F to the query
$query->set(‘search_filter_id’, 26869);$taxquery = array(
array(
‘taxonomy’ => ‘teacher_status’,
‘field’ => ‘slug’,
‘terms’ => array( ‘teacher’ ),
)
);
$query->set( ‘tax_query’, $taxquery );}
}Anonymous(Private) May 24, 2019 at 11:35 pm #212514I have just taken this code out and it still does not work. If I take the shortcode for the search and filter pro searh out, then the pagination works again, so I am not sure what is happening. Happy to share login details if that would help as it is only a staging site
Trevor(Private) May 25, 2019 at 6:00 am #212521Rather than using pre_get_posts, I think you should be using our Edit Query Arguments filter:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
I am in the UK, but often work odd hours. As you can see, I am here right now at 6AM on a Saturday!
pre_get_posts used with our filter has the potential to cause problems.
Anonymous(Private) May 25, 2019 at 9:47 am #212527To be honest I am not sure how to create that function – it’s a bit beyond my abilities.
I tried this, but it made the search form stop working.
function filter_function_name( $query_args, $sfid ) {//if search form ID = 225, the do something with this query
if($sfid==26869)
{
//modify $query_args here before returning it$query_args[‘post_type’] = array( ‘practitioners’ );
}return $query_args;
}
add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );Just to simply matters, I have removed all the functions.php code altogether for the time being. As you will see on the page, the pagination does not seem to work with the search form on the page. When I put in a manual pagination link of https://staging-universallifetools.kinsta.cloud/our-teachers/page/2 it works, but the actual pagination buttons do not seem to do anything, just refresh the page.
-
AuthorPosts