Title: Using Shortcode in Post Meta
Last modified: August 19, 2016

---

# Using Shortcode in Post Meta

 *  Resolved [vavroom](https://wordpress.org/support/users/vavroom/)
 * (@vavroom)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/using-shortcode-in-post-meta/)
 * Hello,
 * I’ve spent the better part of the afternoon trying to make this work, all to 
   no avail! I hope someone will have a pointer for me.
 * I created a shortcode, which works like a charm if I use it in my post content.
   However, if I use it in a custom/meta field, it doesn’t parse at all and gets
   displayed as is.
 * Any idea what might be going on? And more importantly, how I can resolve it?
 * Here’s the code for it:
 *     ```
       function nsg_shortcode( $atts, $content = null ) {
       global $wpdb;
        $querystr = " SELECT $wpdb->posts.post_content, $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->postmeta.meta_value FROM $wpdb->posts
       LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
       WHERE $wpdb->posts.post_status = 'publish'
       AND $wpdb->postmeta.meta_key = 'quickdef'
       AND $wpdb->posts.post_title ='$content' ";
   
        $nsgdata = $wpdb->get_row($querystr, ARRAY_A);
   
       return $content . "<span class=\"pop\"> ( " . $nsgdata['meta_value'] . ")</span> <span class=\"question\">[<a rel=\"nofollow\" href=\"/?p=" . $nsgdata['ID'] ."\" title=\"" . $nsgdata['meta_value'] . "\">?</a>]</span>";
   
        $wpdb->flush();
       }
       add_shortcode('nsg', 'nsg_shortcode');
       ```
   

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

 *  Thread Starter [vavroom](https://wordpress.org/support/users/vavroom/)
 * (@vavroom)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/using-shortcode-in-post-meta/#post-1304013)
 * I know it’s frowned upon to bump a topic, but I could REALLY use some help on
   this and I’m no closer to figuring it out, despite continued testing of various
   ways to accomplish this… Anyone?
 * Thanks
 *  [velofille](https://wordpress.org/support/users/velofille/)
 * (@velofille)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/using-shortcode-in-post-meta/#post-1304015)
 * eval($nsgdata[‘meta_value’])
 *  Thread Starter [vavroom](https://wordpress.org/support/users/vavroom/)
 * (@vavroom)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/using-shortcode-in-post-meta/#post-1304023)
 * With the assistance of a couple people, finally got this working.
 * Instead of calling the custom field like so:
    `echo get_post_meta($post->ID, '
   recipe', true);`
 * I am doing this:
 *     ```
       $nsval = get_post_meta($post->ID, 'recipe', true);
       $nsoutput = do_shortcode( $nsval ) ;
       print $nsoutput;
       ```
   

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

The topic ‘Using Shortcode in Post Meta’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [vavroom](https://wordpress.org/support/users/vavroom/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/using-shortcode-in-post-meta/#post-1304023)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
