1

Im new to Wordpress but I'm looking for a way to loop through all the images that have been uploaded to the media library and output the SRC, description and caption of the image when the caption contains the word 'carousel'.

Is this possible?

6

You could do this pretty easily with a simple query:

global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%carousel%'");
foreach($results as $result){
    //$result->post_id will give you the original attachment post
}

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.