Hey @alexander,
I don’t expect you to debug my shortcode, but this shortcode has literally been working fine for six years until the 9.0.8 update. You could be right that there’s nothing wrong with the theme, but it was the update that made my shortcode only work under certain circumstances. This is the code that runs when the shortcode is called. If you can point out what I’m doing that’s now incompatible with X, I would much appreciate it!
// Add latest sermon player shortcode
function return_latest_am_sermon() {
// Setting up the Query - see http://codex.wordpress.org/Class_Reference/WP_Query
$latest_sermon = new WP_Query(array(
'post_type' => 'wpfc_sermon',
'posts_per_page' => 1,
'post_status' => 'publish',
// Do you want to limit it to a specific service type? Use the service type slug to do it:
// More info here: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
'wpfc_service_type' => 'sunday-am-series',
'order' => 'DESC',
'meta_key' => 'sermon_date',
'meta_value' => date("m/d/Y"),
'meta_compare' => '>=',
'orderby' => 'meta_value',
// The last three parameters will optimize your query
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false
));
if ($latest_sermon->have_posts()) :
?>
<?php while ($latest_sermon->have_posts()) : $latest_sermon->the_post(); ?>
<?php global $post; ?>
<div class="latest-am-sermon">
<a class="latest-sermon-link" title="<?php echo esc_attr( get_the_title() ); ?>" href="<?php the_permalink() ? >"><?php render_sermon_image('full'); ?></a>
<div class="latest-sermon-text">
<h3 class="latest-sermon-title"><?php the_title(); ?></h3>
<h4 class="meta">
<span class="speaker"> <?php the_terms( $post->ID, 'wpfc_preacher', '', ', ', ' ' ); ?>
</span>
</h4>
</div>
<div class="latest-sermon-download">
<?php echo '<a href="' . get_wpfc_sermon_meta('sermon_audio') . '" class="sermon-attachments download- link" title="Download MP3 of ' . esc_attr( get_the_title() ) . '" download>'.__( 'MP3', 'sermon-manager').'</a>'; ?>
</div>
<?php // this will output the media links ?>
<div class="latest-sermon-player"><?php wpfc_sermon_files(); ?></div>
</div>
<?php endwhile; ?>
<?php // reset the $post variable like below: ?>
<?php wp_reset_postdata(); ?>
<?php endif;
}
add_shortcode( 'latest_am_sermon', 'return_latest_am_sermon' );