Forums Forums Search & Filter Pro Turn off / Ignore Results per page setting

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #41475

    Hello,

    I would like to use my own code for displaying number of results but it seems I can’t disable “Results per page” option in S&F. Is there any way to ignore this setting?

    Regards

    Ross Moderator
    #41477

    Unfortunately not, but you could modify the query using this filter

    http://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/#Edit_Query_Arguments

    And add in your own value.

    Thanks

    Anonymous
    #41625

    Can you please explain more. I have this code now but the number of results don’t change

    <?php function results_map_filter( $results_map_args, $sfid ) {
    if($sfid==1530) {
    $results_map_args = array(
    ‘post_type’ => ‘posttype’,
    ‘posts_per_page’ => -1,
    ‘post_status’ => ‘publish’,
    ‘cache_results’ => true,
    ‘no_found_rows’ => true
    );
    }
    return $results_map_args;
    }
    add_filter( ‘sf_edit_query_args’, ‘results_map_filter’, 10, 2 );
    $results_map = get_posts( $results_map_args );
    if (have_posts() ) :
    ?>

    Trevor
    #41626

    I have no idea if your code is roughly correct, but it is not semantically correct.

    It would look like this to be correct from a PHP point of view, I think:

    <?php
    function results_map_filter( $results_map_args, $sfid ) {
      if($sfid==1530) {
        $results_map = get_posts( $results_map_args );
        if (have_posts() ) {
          $results_map_args = array(
            'post_type' => 'posttype',
            'posts_per_page' => -1,
            'post_status' => 'publish',
            'cache_results' => true,
            'no_found_rows' => true
          );
        }
        return $results_map_args;
      }
    add_filter( 'sf_edit_query_args', 'results_map_filter', 10, 2 );
    ?>

    You would use this in your child theme functions.php file, which should already have the opening PHP tag <?php, so you wouldn’t need that from the code, and it is NOT normal to close the PHP tags ?> at the end of the functions.php file as this can cause a site to crash.

    I could well be wrong with the code though.

    Anonymous
    #41632
    This reply has been marked as private.
    Trevor
    #41633
    This reply has been marked as private.
    Ross Moderator
    #41634

    There shouldn’t be a custom query inside the filter itself, the filter is used to modify the arguments before they get passed to a query – the code should look like:

    function results_map_filter( $query_args, $sfid ) {
    	
    	//if search form ID = 1530, the do something with this query
    	if($sfid==1530)
    	{
    		//modify $query_args here before returning it
    		$query_args['posts_per_page'] = -1;
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'results_map_filter', 10, 20 );

    Thanks

    Anonymous
    #42349

    Thank you Ross. Must I call then this function in my template (where…before loop)? Cheers

    Ross Moderator
    #43325

    Just seen this – sorry for the delay – this should go in your functions.php file

Viewing 9 posts - 1 through 9 (of 9 total)