![](/img/trans.png)
[英]WordPress: get all posts included in two taxonomies (WP_Query tax_query relation AND)
[英]WP_Query Get all Posts by category with Tags included
嘗試獲取具有各自標簽的類別中的所有帖子。
使用$args = array('numberposts' => 100,'category_name' => 'someCategory' ); $arr = get_posts( $args );
$args = array('numberposts' => 100,'category_name' => 'someCategory' ); $arr = get_posts( $args );
但是與每個帖子相關的標簽不在WP_Post Objects數組中。
不清楚是否需要將此設置為其他arg或在循環內調用另一個函數?
提前致謝!
是的,您需要在循環中調用另一個函數,它可能是get_the_terms()
,例如:
foreach( $arr as $post ) {
// function will return an array of objects of assigned tags
print_r( get_the_terms( $post->ID, 'post_tag' ) );
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.