• Hi,

    we’ve a custom LISTINGS template and we’d like to display just 5 locations. Changing max_results didn’t do anything within the code in function.php. Is there a way to change the query or the listing, so we would get just 5 results?

    Note: This can be changed in the admin (and then it works with the max results set in the admin), but we would like to keep 50 results for the “general” map (and not to show just 5 results).
    In function.php we use two filters, so if the change is possible within them, it would be great:
    function custom_listing_template()
    function custom_templates( $templates )

    Thank you!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    There’s a ‘wpsl_js_settings‘ filter, so you can use to to set different values based on the page you’re on.

    Or is this the thing you tested already, and didn’t work?

    Thread Starter rombaaa

    (@rombaaa)

    Thank you for reply, Tijmen.
    I tried changing only $wpsl_settings within the template (or in the functions.php as shown below), unfortunately this didn’t work. I tried changing wpsl_js_settings, but the same – anyway, isn’t it needed just for the map? We’re not loading any map, just the listing of locations and we need only one – the closest to the user. This should be send on every page.

    Any help would be appreciated.

    Here is the code in the functions.php.

    add_filter( ‘wpsl_templates’, ‘custom_templates’ );
    function custom_templates( $templates ) {
    $templates[] = array (
    ‘id’ => ‘custom’,
    ‘name’ => ‘Custom template’,
    ‘path’ => get_stylesheet_directory() . ‘/’ . ‘wpsl-templates/custom.php’,
    );
    return $templates;
    }

    add_filter( ‘wpsl_listing_template’, ‘custom_listing_template’ );
    function custom_listing_template() {
    global $wpsl_settings;
    // $wpsl_settings[‘max_results’]=’1′;
    $listing_template = ‘<li data-store-id=”<%= id %>”>’ . “\r\n”;
    $listing_template .= “\t\t\t” . ‘“>YOUR K1 SPEED<br />’ . “\r\n”;
    $listing_template .= “\t\t\t\t” . wpsl_store_header_template( ‘listing’ ) . “\r\n”;
    $listing_template .= “\t\t\t” . ‘
    ‘ . “\r\n”;
    $listing_template .= “\t” . ‘‘ . “\r\n”;
    return $listing_template;
    }

    Plugin Author Tijmen Smit

    (@tijmensmit)

    This code works, but you do have to disable the max results dropdown on the settings page.

    
    add_filter( 'wpsl_js_settings', 'custom_wpsl_js_settings' );
    
    function custom_wpsl_js_settings( $args ) {
    
        if ( is_page( 'wpsl' ) ) {
            $args['maxResults'] = 10;
        } else if ( is_page( 'wpsl-2' ) ) {
            $args['maxResults'] = 20;
        }
    
        return $args;
    
    }
    

    Replace wpsl and wpsl-2 with the permalinks from your own page.

    Thread Starter rombaaa

    (@rombaaa)

    Hello Tijmen,

    thank you for the update. I’ve tried it and still no results – I’ve the max results drop down unchecked ??

    I’m using is_page_template instead of the is_page. I’m printing also the template name, to check that the correct the code runs, but somehow the args are not taken into account.
    I’ve added $wpsl_settings[‘max_results’]=’1′ as well, but neither this change the number of results.

    To be more precise, I’m not allowing (denying) location on my browser to test the number of result, just in case the plugin somehow depends on it.

    Any idea, why it is not working?

    Thank you and happy new year!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom listings template max result’ is closed to new replies.