我想创建一个短代码,它只显示具有明确meta\\u值的帖子。我将ACF插件用于不同的元字段。我的帖子类型为“publication”,例如,我只想显示2017年发布的带有此短代码[publication 2017]或publication release Date 2017]的出版物。
function shortcode_display_publication_details(){
$args = array(
\'post_type\' => \'publication\',
\'posts_per_page\' => -1,
\'meta_key\' => \'release-date\',
\'meta_value\' => \'2017\',
\'orderby\' => \'meta_value\',
\'order\' => \'DESC\',
\'post_status\' => \'publish\'
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
echo the_field(\'autor\'). " (" ;
echo the_field(\'release-date\'). ") ";
echo the_field(\'buch\'). ". ";
echo \'<b>\' . get_the_title() . \'</b>\'. ", ";
echo the_field(\'verleger\'). ". " ;
if (get_field(\'seiten\')){
echo "S. ";
echo the_field(\'seiten\'). ". <p />" ;
}
echo \'<p>\';
echo \' \';
endwhile;
// Restore original Post Data
wp_reset_postdata();
}
// Register the shortcodes.
add_shortcode( \'publication\', \'shortcode_display_publication_details\' );
此短代码仅显示2017年的出版物。但我不想每年都建立一个额外的短代码。它是如何工作的,我可以创建一个具有自定义meta\\u值的短代码,如[发布年份xxxx]?非常感谢您的帮助!