• Resolved dailygives

    (@dailygives)


    What is the short code to just list by location?

    [advert_list location=5]

    Something like that?

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    You can add the code below to your theme functions.php file

    
    add_filter( "shortcode_atts_adverts_list", "my_custom_shortcode_atts", 10, 3 );
    add_filter( "adverts_list_query", "my_custom_shortcode_param", 10, 2 );
    function my_custom_shortcode_atts( $out, $pairs, $att ) {
        $out["_location"] = "";
        if(isset($att["_location"])) {
            $out["_location"] = $att["_location"];
        }
        return $out;
    }
    function my_custom_shortcode_param($args, $params) {
        if(!empty($params["_location"])) {
            $args["meta_query"][] = array('key'=>'adverts_location', 'value'=>$params["_location"], 'compare'=>'LIKE');
        }
        return $args;
    }
    

    it will register “_location” param in the [adverts_list] shortcode, so now you will be able to use the shortcode as

    
    [adverts_list _location="New York"]
    

    the displayed results should be exactly the same as when entering “New York” in location input.

    Thread Starter dailygives

    (@dailygives)

    I had the code working this morning, but I am unable to replicate what I had. I even restored my website to a back up point to start from scratch.. Is another option to list by location?

    Thread Starter dailygives

    (@dailygives)

    Update****

    So the function is just returning any listing that I have updated the location with the google api that automatically generates a location category.

    See example below:
    https://thegaylordboxexchange.com/5-ply-gaylord-boxes/

    I entered these 6 variations to my page and they all return the same results. The result I used an old location category that I previously entered. Still I get the same results.

    [adverts_list _location=”CA”]

    [adverts_list _location=”California”]

    [adverts_list _location=”Chicago”]

    [adverts_list _location=”Illinois”]

    [adverts_list _location=”illinois”]

    [adverts_list _location=”Glendale”]

    Thread Starter dailygives

    (@dailygives)

    I entered these 6 shortcode variations into to my page and each one of them returned the same listings. As for the 6th shortcode, I used an old location category that I had previously entered.***

    Plugin Author Greg Winiarski

    (@gwin)

    I see you are aslo using the MAL add-on, it will not work with the above code snippet, you would need to disable the MAL search as it accepts search params from the query string only, modify the my_custom_shortcode_param() function to look like this

    
    function my_custom_shortcode_param($args, $params) {
        if(!empty($params["_location"])) {
            remove_filter( "adverts_list_query", "wpadverts_mal_search_location" );
            $args["meta_query"][] = array('key'=>'adverts_location', 'value'=>$params["_location"], 'compare'=>'LIKE');
        }
        return $args;
    }
    
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘List ads by location’ is closed to new replies.