-2
如何使用SELECT
WordPress查询在分类学slu help的帮助下获取自定义帖子类型?分类学在wordpress中使用slu 012获取
如何使用SELECT
WordPress查询在分类学slu help的帮助下获取自定义帖子类型?分类学在wordpress中使用slu 012获取
您不需要使用SELECT
在分类学slu help的帮助下获取自定义文章。
WordPress为我们提供了get_posts函数来检索符合给定条件的帖子列表。
$posts_array = get_posts(
array(
'posts_per_page' => -1, //-1 is to retrieve all posts.
'post_type' => 'my_custom_post', //specify your custom post.
'tax_query' => array(
array(
'taxonomy' => 'my_taxonomy' //taxonomy on which you are going to find posts
)
)
)
);
您必须使用WP_Query来获取所需的帖子。在你的情况下,查询可能是这样的:
<?php
$the_query = new WP_Query(array(
'post_type' => 'my_custom_post',
'tax_query' => array(
'taxonomy' => 'my_custom_taxonomy',
'field' => 'slug',
'terms' => 'my_custom_taxonomy_slug',
),
));
while ($the_query->have_posts()) :
$the_query->the_post();
// Show Posts ...
endwhile;
/* Restore original Post Data */
wp_reset_postdata();
?>
Click here要阅读它的文档。
“帖子”不是自定义帖子类型。它是默认的帖子类型。 你能否整齐地阐述你的问题? – WisdmLabs