我检查过你的代码不正确。
请使用以下代码。
<?php
add_shortcode( 'events', 'callback_function_name' );
function callback_function_name( $atts, $shrt_content = null ) {
// Shortcode Parameter
$atts = shortcode_atts(array(
'category' => ''
), $atts, 'events');
$categories = ! empty( $atts['category'] ) ? explode( ',' , $atts['category'] ) : '';
extract( $atts );
// Query args
$query_args = array(
'post_type' => 'event',
'post_status' => 'publish',
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'posts_per_page' => -1,
'tax_query' => array( array(
'taxonomy' => 'category',
'field' => 'slug',
'operator' => 'AND',
'terms' => $categories
) )
);
// WP Query for Events
$post_query = new WP_Query( $query_args );
ob_start();
// If post is there
if ( $post_query->have_posts() ) {
while ( $post_query->have_posts() ) : $post_query->the_post(); ?>
<div><?php the_title(); ?></div>
<div><?php the_content(); ?></div>
<?php endwhile;
} else { ?>
<p>* no events listed at this time...</p>
<?php }
wp_reset_postdata(); // Reset WP Query
$content .= ob_get_clean();
return $content;
}