您可以使用get\\u posts内置函数更改meta\\u键和meta\\u值
$args = array(
\'meta_key\' => \'YOUR_META_KEY\',
\'meta_value\' => \'featured\',
\'post_type\' => \'YOUR_POST_TYPE\',
\'post_mime_type\' => \'\',
\'post_parent\' => \'\',
\'author\' => \'\',
\'author_name\' => \'\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true
);
$posts_array = get_posts( $args );
foreach ( $posts_array as $post ) : setup_postdata( $post ); ?>
<li>
<span><?php echo esc_attr( $post->ID ); ?></span>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach;
// MUST Reset
wp_reset_postdata();
注意:不要修改本地foreach变量[$post]
有关更多详细信息,请参阅WordPress get_posts function