WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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