我正在处理函数内部的自定义短代码函数。php将显示“speakers”帖子类型,带有“featured speaker”ACF复选框,并按ACF select元素设置的特定顺序显示。Bt自定义短代码不显示任何内容。我已经检查了很多次代码,但我无法发现我做错了什么。
add_shortcode( \'featured_speakers_clzd\', \'custom_speakers_clzd\' );function custom_speakers_clzd() {
$args = array(
\'post_type\' => \'speaker\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'key\' => \'featured_speaker\',
\'value\' => \'1\',
\'compare\' => \'=\',
),
array(
\'key\' => \'speaker_order\',
\'orderby\' => \'meta_value\',
\'order\' => DESC,
),
),
);
$query = new WP_Query( $args );
$out = \'\';
$out .= \'<div class="full_section_inner">\';
if ( $query->have_posts() ) {
// The Loop
while ( $query->have_posts() ) {
$query->the_post();
$out .= \'<div class="vc_col-sm-3">\';
$out .= \'<div class="wpb_single_image">\';
$out .= \'<a href="\'.get_field(\'speaker_link\').\'" target="_blank">\';
$out .= \'<div class="vc_single_image-wrapper vc_box_border_circle vc_box_border_grey">\';
//$out .= \'<img width="150" height="150" src="http://growcommerce.co/wp-content/uploads/2016/06/0c02f46-150x150.jpg" class="vc_single_image-img attachment-thumbnail" alt="Miki Beradelli, CEO, Kidbox" srcset="http://growcommerce.co/wp-content/uploads/2016/06/0c02f46-150x150.jpg 150w, http://growcommerce.co/wp-content/uploads/2016/06/0c02f46.jpg 296w" sizes="(max-width: 150px) 100vw, 150px">\';
$out .= get_the_post_thumbnail( get_the_ID(), \'thumbnail\' );
$out .= \'</div>\';
$out .= \'</a>\';
$out .= \'</div>\';
$out .= \'<div class="separator transparent"></div>\';
$out .= \'<div class="wpb_text_column wpb_content_element ">\';
$out .= \'<div class="wpb_wrapper">\';
$out .= \'<p style="text-align: center;">\';
$out .= \'<a href="https://www.linkedin.com/in/miki-racine-berardelli-b0022b3/" target="_blank">\';
$out .= \'<span style="color: #ffffff;">\'.get_the_title().\'</span>\';
$out .= \'</a>\';
$out .= \'</p>\';
$out .= \'<p style="text-align: center;">\';
$out .= \'<a href="\'.get_field(\'speaker_link\').\'" target="_blank">\';
$out .= \'<span style="color: #ffffff;">\'.get_field(\'company\').\'</span>\';
$out .= \'</a>\';
$out .= \'</p>\';
$out .= \'</div>\';
$out .= \'</div>\';
$out .= \'<div class="separator transparent"></div>\';
$out .= \'</div>\';
}
wp_reset_postdata();
}
$out .= \'</div>\';
return $out;
}
SO网友:rudtek
try this:
$args = array(
\'post_type\' => \'speaker\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\',
\'meta_query\' => array(
array(
\'key\' => \'featured_speaker\',
\'value\' => \'1\',
\'compare\' => \'=\',
),
),
\'orderby\' => \'meta_value\',
\'meta_key\' => \'speaker_order\',
\'order\' => DESC,
);