I need to obtain all media data from wp_posts table that are embeded in a specific post category.

In other words, I need all media data from elementes incrusted in a list of posts elements.

But I don't know even where start to search...



You could work on a WP_Query of posts of your category and then use get_attached_media to find the media of each one of the posts found. You could do a more specific query there, it's up to you!

// 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() ) {
        // 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.