你可以在WP_Query ,然后使用get_attached_media 查找找到的每个帖子的媒体。你可以在那里进行更具体的查询,这取决于你!
// WP_Query arguments
$args = array(
\'category_name\' => \'name_of_your_category\',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// Adds all the media attached to each post found in the query
// This is just an example of how you could use it!
array_push( $your_array, get_attached_media( \'image\', get_the_ID() ) );
}
} else {
// no posts found
}
// Restore original Post Data
wp_reset_postdata();