我为自定义post类型查询创建了一个快捷码,但当我向其中添加meta\\u查询值时,它会抛出一个错误:
Notice: Undefined variable: my in E:\\xampp\\htdocs\\test\\wp-content\\themes\\test-theme\\functions.php on line 182
以下是短代码:
function list_unit( $atts ) {
$args = array(
\'post_type\' => \'unit\',
\'posts_per_page\' => -1,
\'post_parent\' => \'0\',
\'orderby\' => \'menu_order\',
\'meta_query\' => array(
array(
\'key\' => \'first_item_key\',
\'value\' => \'false\',
\'compare\' => \'=\'
)
),
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$my = \'<table>\';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$my .= \'<tr><td><a href="\'. get_the_permalink() .\'">\';
$my .= get_the_title() ;
$my .= \'</a></td></tr>\';
}
$my .= \'</table>\';
} else {
// no posts found
}
return $my;
}
add_shortcode( \'unit\', \'list_unit\' );
不确定出了什么问题。