I have the following query:
// WP_Query arguments
$args = array (
'posts_per_page' => '6',
'post_type' => 'attachment',
'meta_query' => array(
array(
'key' => 'galeriaimg',
'value' => 'sim',
),
),
);
// The Query
$attachment = new WP_Query( $args );
// The Loop
if ( $attachment->have_posts() ) {
while ( $attachment->have_posts() ) {
$img_url = wp_get_attachment_url( $attachment->ID, 'medium', false );
$img_url_full = wp_get_attachment_url( $attachment->ID, 'large', false );
echo '<a class="fancybox" href="'.$img_url_full.'">';
echo '<img src="'.$img_url.'">';
echo '</a>';
}
} else {
echo '<h1>ERRO1</h1>';
}
// Restore original Post Data
wp_reset_postdata();
?>
For some reason, after I added the custom field (meta key) in the query, it stopped returning the images. I already checked the database and the images are related to the meta key, all right, including the value.
What's the problem?