我建议使用WP_Query()
相反像这样:
<?php
$category = \'whatever\';
$new_query = new WP_Query(
array(
\'post_type\' => \'post\',
\'posts_per_page\' => -1,
\'category_name\' => $category;
)
);
if ($new_query->have_posts()) {
$i = 0;
while ($new_query->have_posts()) {
$new_query->the_post();
$postid = get_the_ID();
// Your output code.
}
}
wp_reset_postdata();
?>
仅仅是改变
$category
无论你需要什么。如果要有多个类别,请将其设置为array()
但是,如果要对自定义帖子类型执行此操作,则需要使用
tax_query
数组,如下所示:
\'tax_query\' => array(
array(
\'taxonomy\' => \'people\',
\'field\' => \'slug\',
\'terms\' => \'bob\',
),
),
上述示例直接取自
WordPress Codex.