Forums

[resolved] Shortcode Within A get_post (3 posts)

  1. visualadvance
    Member
    Posted 1 year ago #

    Let me see if I can explain this.

    1. In my template I am using this code to display a single post:
    $my_post_id = get_post ($postid);
    $my_content = $my_post_id->post_content;
    echo $my_content;

    2. There is a shortcut inside of the post that I am pulling with the above function. But when I pull that post using the get_post listed above, it gets returned as a string and the shortcode isn't executed. So when I do the get_post above, it ends up displaying the post as:
    Blah blah blah [my_shortcode_function foo="bar"] blah blah

    Any clues on how I can modify the get_post call in order to not turn any shortcodes into literal strings?

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    try:

    echo apply_filters('the_content', $my_content);

    http://codex.wordpress.org/Function_Reference/apply_filters

    or

    echo do_shortcode( $my_content );

    http://codex.wordpress.org/Function_Reference/do_shortcode

    or (if you don't want the shortcode)

    echo strip_shortcodes( $my_content );

    http://codex.wordpress.org/Function_Reference/strip_shortcodes

    (all untested)

  3. visualadvance
    Member
    Posted 1 year ago #

    You are a genius.

    I didn't try apply_filters yet, but do_shortcode did exactly what I needed. Much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic