尽管我是100%肯定的,$mixtape\\u id设置为一个整数,该整数对应于“mixtaples”自定义post类型中的一个post,但此代码没有响应任何内容
$query = new WP_Query(array(
\'post_type\' => \'mixtapes\',
\'p\' => (int)$mixtape_id,
\'posts_per_page\' => -1,
\'orderby\' => \'meta_value_num\',
\'meta_key\' => \'track_number\'
));
while ( $query->have_posts() ) : $query->the_post(); ?>
<track>
<location>track1.mp3</location>
<creator>Artist name</creator>
<title>Track 1</title>
</track>
<?php endwhile; ?>
最合适的回答,由SO网友:Tallboy 整理而成
我用不同的方法解决了这个问题
$query = new WP_Query(array(
\'post_type\' => \'tracks\',
\'posts_per_page\' => -1,
\'orderby\' => \'meta_value_num\',
\'meta_key\' => \'track_number\',
\'meta_query\' => array(
array(
\'meta_key\' => \'mixtape\',
\'meta_value\' => (string)$mixtape_id
)
)
));