I'm trying to return all the images within the media library that have a custom field with the value of True
.
For some reason nothing is being returned, this is what I have so far:
function showPainted() {
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => - 1,
'meta_key' => 'show_on_painted_page',
'meta_value' => '1'
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image ) {
$images[] = wp_get_attachment_url( $image->ID );
}
print_r($images);
}
add_shortcode( 'showPainted', 'showPainted' );
Can anyone help me with this one?