简体   繁体   中英

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 );

But the tags related to each post are not in the WP_Post Objects array.

Unclear if I need to set this as an additional arg or call another function within the loop?

Thanks in advance!

Yes, you need to call another function within your loop, it could be get_the_terms() , example:

foreach( $arr as $post ) {
    // function will return an array of objects of assigned tags
    print_r( get_the_terms( $post->ID, 'post_tag' ) );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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