This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Tagged: 

Do Shortcode in Mini Post List Pluggable

  • Creator
    Topic
  • #22211
    kennethfeldman
    Participant

    Hi Jason,

    I’ve successfully copied the Mini Posts List function to my Functions.php, and have slightly modified the output to include the post_excerpt per your recent notes.

    However, I am now wanting to add a shortcode to my Mini Post List output.

    I can get any shortcode itself (still in the brackets, un-rendered) to print out to the page, but how do I get it to execute? Is there a way?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #22212
    Jason Bobich
    Keymaster

    What is your current code that’s straight printing it out?

    #22213
    kennethfeldman
    Participant


    $output .= '<div class="mini-post-list-content">';
    $output .= sprintf( '<h4>%s</h4>', themeblvd_get_the_title( $post->ID, true ) );
    $output .= '<div class="faculty-details">[ct id="_ct_textarea_55895c91d60ff" property="title | description | value"]</div>';

    #22215
    kennethfeldman
    Participant

    Per my previous support request I had:

    $output .= '<div class="faculty-details">' . $excerpt = get_the_excerpt( $deprecated ) . '</div>';

    …which worked fine, however I want to replace the_excerpt with a shortcode from a custom post type plugin.

    Note that ANY shortcode results in getting printed straight out.

    #22225
    Jason Bobich
    Keymaster

    First off, this:

    $output .= '<div class="faculty-details">' . $excerpt = get_the_excerpt( $deprecated ) . '</div>';

    Should be this:

    $output .= '<div class="faculty-details">' . get_the_excerpt() . '</div>';

    And with your new code, this:

    $output .= '<div class="faculty-details">[ct id="_ct_textarea_55895c91d60ff" property="title | description | value"]</div>';

    Would simply become this:

    $output .= '<div class="faculty-details">' . do_shortcode('[ct id="_ct_textarea_55895c91d60ff" property="title | description | value"]') . '</div>';
    #22226
    Jason Bobich
    Keymaster

    In WordPress if you want to execute shortcodes, you pass the string of text into do_shortcode(). This function then returns the string back to you, but with shortcodes executed.

    $str = '[foo this="that"]';
    
    // Print out above string, no shortcode executed
    echo $str;
    
    // Print out above string, with shortcode executed
    echo do_shortcode($str);
    
    // Save above string to a variable, with shortcode executed
    $new_str = do_shortcode($str);

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

    When you’re looking at these codex pages, don’t just copy from the top of the article where it says “Usage” — Look below at the actual examples, and try to gain an understanding of the basic principles of using functions in PHP.

    For example, above where you did this:

    $output .= '<div class="faculty-details">' . $excerpt = get_the_excerpt( $deprecated ) . '</div>';

    … This tells me you’re just copying from the top of the codex page without really understanding what you’re copying. So try to look at whatever more in-depth examples are provided so you can start to learn these basic things. You’ll start to see the patterns and get a basic understanding for PHP.

    #22237
    kennethfeldman
    Participant

    Awesome, thanks Jason.

    This did the trick. I thought I had tried this, but must have had a typo.

    $output .= '<div class="faculty-details">' . do_shortcode('[ct id="_ct_textarea_55895c91d60ff" property="title | description | value"]') . '</div>';

    Further, I have several extra fields in a particular post type, and so I added some IF’s around them and now my mini posts lists kick out different extra field data depending on which page they appear. Very cool.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.