Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created September 26, 2011 20:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save billerickson/1243289 to your computer and use it in GitHub Desktop.
Save billerickson/1243289 to your computer and use it in GitHub Desktop.
Get images marked "Include in Rotator"
<?php
// Get all images attached to post that have "Include in Rotator" marked as "Yes"
global $post;
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => '-1',
'order' => 'ASC',
'orderby' => 'menu_order',
'meta_query' => array(
array(
'key' => 'be_rotator_include',
'value' => '1'
)
)
);
$images = new WP_Query( $args );
if( !$images->have_posts() )
return;
while( $images->have_posts() ): $images->the_post(); global $post;
// Echo image url
$image = wp_get_attachment_image_src( $post->ID, 'be_featured' );
echo $image[0] . '<br />';
endwhile; wp_reset_query();
@Markj89
Copy link

Markj89 commented Oct 28, 2016

This is a very handy function, Thank you

I'm trying to add a dropdown field, which already has a number of value, it outputs onto the media uploader, but it doesn't save.
How do I get it to save? Could I send you my file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment