Title: Template shortcode variable with query
Last modified: August 31, 2016

---

# Template shortcode variable with query

 *  [tabby1011](https://wordpress.org/support/users/tabby1011/)
 * (@tabby1011)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/template-shortcode-variable-with-query/)
 * Hi
 * I tried adding a mysql query for the $address variable to call in the shortcode
   but it’s not working:
 * `('[google_map version="classic" lang="en" link="yes" width="200" height="200"]'.
   $address.'[/google_map]');`
 * This was the query I created in the variable:
 * `$address = "select address from map where Title in (select post_title from wp_posts
   where ID = '29') AND active='1'";`
 * Can someone help me with this please.
 * [https://wordpress.org/plugins/embed-google-map/](https://wordpress.org/plugins/embed-google-map/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [petkivim](https://wordpress.org/support/users/petkivim/)
 * (@petkivim)
 * [10 years ago](https://wordpress.org/support/topic/template-shortcode-variable-with-query/#post-7317695)
 * Hi,
 * You should fetch the address from the database before adding the shortcode. The
   below syntax for the db query is not correct, but you should get the idea in 
   which order things should done.
 *     ```
       $sql = "select address from map where Title in (select post_title from wp_posts where ID = '29') AND active='1'";
       $addresses = $wpdb->get_results($sql, ARRAY_N);
   
       ('[google_map version="classic" lang="en" link="yes" width="200" height="200"]' . $addresses[0]['address'] . '[/google_map]');
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Template shortcode variable with query’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/embed-google-map.svg)
 * [Embed Google Map](https://wordpress.org/plugins/embed-google-map/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/embed-google-map/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/embed-google-map/)
 * [Active Topics](https://wordpress.org/support/plugin/embed-google-map/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/embed-google-map/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/embed-google-map/reviews/)

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 1 reply
 * 2 participants
 * Last reply from: [petkivim](https://wordpress.org/support/users/petkivim/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/template-shortcode-variable-with-query/#post-7317695)
 * Status: not resolved