• Resolved vavroom

    (@vavroom)


    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

    (@vavroom)

    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

    eval($nsgdata[‘meta_value’])

    Thread Starter vavroom

    (@vavroom)

    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.