The year attribute you added to shortcode [speaker_overview_2017 year=2017]
will be available through $atts
in this way $atts['year']
. I assume, you want to do a meta query and the key is speakers_jaar
and the value will be $atts['year']
. Please check the following code. When a year is set in shortcode, query will be limited to that year otherwise not limited.
function speakers_overview_shortcode( $atts ) {
$atts = shortcode_atts( array(
'year' => ''
), $atts );
$args = array(
'post_type' => 'qp_speakers',
'post_status' => 'publish',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1,
);
if ( ! empty( $atts['year'] ) ) {
$args['meta_query'] = array(
array(
'key' => 'speakers_jaar',
'value' => absint( $atts['year'] ),
)
);
}
$locaties = new WP_Query( $args );
ob_start();
if ( $locaties->have_posts() ) :
while ( $locaties->have_posts() ) {
$locaties->the_post();
q2_speakers_template();
}
}
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode( 'speaker_overview_2017', 'speakers_overview_shortcode' );