At it’s easiest something very similar to the count problem you posed yesterday:
<?php
$cat_name = 'Image';
$custom_field = 'Main Image';
$cat_id = get_cat_ID($cat_name);
$args=array(
'cat' => $cat_id,
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of Posts in category ' . $cat_name . ' with custom field ' . $custom_field ;
while ($my_query->have_posts()) : $my_query->the_post();
$image = get_post_meta($post->ID, $custom_field, true);
if ($image){ ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
}
endwhile;
}
if( $my_query->have_posts() ) {
echo 'List of Posts in category ' . $cat_name . ' without the custom field ' . $custom_field;
while ($my_query->have_posts()) : $my_query->the_post();
$image = get_post_meta($post->ID, $custom_field, true);
if (!$image){ ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
}
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>