-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