Title: Shortcode for location
Last modified: March 15, 2021

---

# Shortcode for location

 *  Resolved [titusb](https://wordpress.org/support/users/titusb/)
 * (@titusb)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-for-location/)
 * Hi Greg,
 * you wrote here [https://wordpress.org/support/topic/location-url-adjustment/](https://wordpress.org/support/topic/location-url-adjustment/)
   that it is possible to predefine the location of adverts through the shortcode.
   In the post you mention the locations term ID. Where do I get it from since my
   users only type in a city’s name? Ad is it possible to add the locations name
   in the shortcode instead?
 * Thank you!
    Titus

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-for-location/#post-14188215)
 * Hi,
    please note that this thread was related to the Maps and Locations extension(
   against the forum rules though), in order to be able to use the code i pasted
   there you would need to have the MAL extension [https://wpadverts.com/extensions/maps-and-locations/](https://wpadverts.com/extensions/maps-and-locations/)
   installed and configured.
 *  Thread Starter [titusb](https://wordpress.org/support/users/titusb/)
 * (@titusb)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-for-location/#post-14199756)
 * I see, thank you!
 * So when I understand it right, there is no possibility without MAL to produce
   the same result that user get by entering a location in the search field through
   a specific location-defining shortcode?
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-for-location/#post-14205293)
 * Hi,
    yes, this is possible only with the Maps and Locations extension only, sorry.
 * I mean, it is also possible to custom code something like that, but doing so (
   most likely) would be more expensive than getting the Pro package.
 * One other option would be to change the my_custom_shortcode_param function from
   the linked thread to
 *     ```
       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;
       }
       ```
   
 * Then use [adverts_list] as `[adverts_list _location='my location']` where ‘my
   location’ is a part (or whole location) user entered in the Location field when
   posting an Ad.
 * For example, if you have an Ad with Location “New York” then using the shortcode
   as `[adverts_list _location="York"]` should show this Ad.
 * So this is possible without the MAL but will not be as accurate as when using
   the location taxonomy.
 *  Thread Starter [titusb](https://wordpress.org/support/users/titusb/)
 * (@titusb)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-for-location/#post-14210385)
 * You are amazing, thank you Greg!
 * I think this is a really good point to start with! At the moment I’m totally 
   fine with the disadvantages of this approach. In case people really start using
   our site we’ll step up to MAL I guess.
 * All the best!
    Titus

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Shortcode for location’ is closed to new replies.

 * ![](https://ps.w.org/wpadverts/assets/icon-256x256.png?rev=2423472)
 * [WPAdverts - Classifieds Plugin](https://wordpress.org/plugins/wpadverts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpadverts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpadverts/)
 * [Active Topics](https://wordpress.org/support/plugin/wpadverts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpadverts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpadverts/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [titusb](https://wordpress.org/support/users/titusb/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-for-location/#post-14210385)
 * Status: resolved