【发布时间】:2020-05-28 20:15:48
【问题描述】:
我正在尝试按分类获取自定义帖子类型中所有帖子的列表,我在这段代码中被困了 3 天,现在我和父亲一起学习,他给了我一个提示,为什么我的代码不起作用一个说我有太多的参数我会告诉你代码我希望任何人都可以帮助我理解为什么它不工作,也许如果你真的用英文解释代码
print_r(Array(
"1"=>"first",
"2"=>"second"
));
// just try to remove args that you don't need
//actually you need only one
$args = array(
'tax_query' => array(
'taxonomy' => 'your-custom-taxonomy',
'field' => 'slug',
'terms' => array( 'your-term' )
),
'post_type' => 'your-post-type'
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
$term = $wp_query->queried_object;
while($loop->have_posts()) : $loop->the_post();
//Output what you want
echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
endwhile;
}
【问题讨论】:
标签: javascript php wordpress list