Limit search results (not location listings)

This topic contains 2 replies, has 3 voices, and was last updated by  Kiran 5 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #442827

    Kevin Holdridge
    Full Member
    Post count: 45

    When user does a ‘near’ search I’d like to show only the first 5 results. But I don’t want to constrain the display on location pages or on the default view before any filters have been applied. Is there an easy way to achieve this?

    #442874

    Paolo
    Site Admin
    Post count: 31206

    I’m sure there isn’t an option to achieve that, but I flagged this for the developer to see if with a hook it can be done.

    They’ll let you know asap.

    Thanks

    #443124

    Kiran
    Moderator
    Post count: 7069

    Hello Kevin,

    Please try following snippet code.

    
    
    /* Set posts limit on near results search */
    function _gd_custom_set_posts_per_page( $wp_query ) {
    	if ( ! empty( $_REQUEST['geodir_search'] ) && ! empty( $_REQUEST['sgeo_lat'] ) && ! empty( $_REQUEST['sgeo_lon'] ) && ! empty( $wp_query ) && $wp_query->is_main_query() ) {
    		$wp_query->set( 'posts_per_page', 5 ); // Your posts per page limit
    	}
    	return $wp_query;
    }
    add_action( 'pre_get_posts', '_gd_custom_set_posts_per_page', 100, 1 );

    Thanks,
    Kiran

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

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket