简体   繁体   English

WP_Query按类别获取所有带有标签的帖子

[英]WP_Query Get all Posts by category with Tags included

Trying to get all posts in a category with their respective tags. 尝试获取具有各自标签的类别中的所有帖子。

Using $args = array('numberposts' => 100,'category_name' => 'someCategory' ); $arr = get_posts( $args ); 使用$args = array('numberposts' => 100,'category_name' => 'someCategory' ); $arr = get_posts( $args ); $args = array('numberposts' => 100,'category_name' => 'someCategory' ); $arr = get_posts( $args );

But the tags related to each post are not in the WP_Post Objects array. 但是与每个帖子相关的标签不在WP_Post Objects数组中。

Unclear if I need to set this as an additional arg or call another function within the loop? 不清楚是否需要将此设置为其他arg或在循环内调用另一个函数?

Thanks in advance! 提前致谢!

Yes, you need to call another function within your loop, it could be get_the_terms() , example: 是的,您需要在循环中调用另一个函数,它可能是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM