0
votes

Working with a plugin that provides a shortcode with only a couple of parameters. https://wordpress.org/plugins/radio-station I'm using the [list-shows] shortcode. I would like to also pull in an excerpt of the content, I imagine that would be applicable to a lot of situations and improve my understanding of shortcodes.

I was able to add in the thumbnail to the output, but not the content, which seems to be referred to in the atts of the other shortcodes as 'show_desc'. You can see the output on this page: http://www.kzmuradio.org/kzmu-programs/

Here is the code for the shortcode. Apologies for my ignorance. Learning curve.

/* Shortcode for displaying a list of all shows * Since 2.0.0*/
function station_shortcode_list_shows($atts) {
extract( shortcode_atts( array(
        'genre' => '',
        'show_desc' => 1
), $atts ) );

//grab the published shows
$args = array(
        'numberposts'     => -1,
        'offset'          => 0,
        'orderby'         => 'title',
        'order'           => 'ASC',
        'post_type'       => 'show',
        'post_status'     => 'publish',
        'meta_query' => array(
                array(
                        'key' => 'show_active',
                        'value' => 'on',
                )
        )
);

if($genre != '') {
    $args['genres'] = $genre;
}

$shows = get_posts($args);

//if there are no shows saved, return nothing
if(!$shows) {
    return false;
}

$output = '';

$output .= '<div id="station-show-list">';
$output .= '<ul>';
foreach($shows as $show) {


$output .= '<li>' . get_the_post_thumbnail($show->ID, 'thumbnail') . '<a href="'.get_permalink($show->ID).'">'.get_the_title($show->ID).'</a></li>';

    $output .= '</li>';
}
$output .= '</ul>';
$output .= '</div>';
return $output;
1

1 Answers

0
votes

You can access all the data through $show in your foreach-loop. To see what they contain, you can use print_r():

print_r( $show );

For excerpt and content you can use this:

echo $show->post_excerpt;
echo wpautop( $show->post_content );

See also: https://codex.wordpress.org/Function_Reference/$post