Interesting issue here.
I have this:
$args=array(
'meta_key'=>'_simple_fields_fieldGroupID_1_fieldID_8_numInSet_0',
'post_type' => 'stores',
'post_status' => 'publish',
'posts_per_page' => 10,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<ul><li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php $selected_value = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_9_numInSet_0", true);
echo "$selected_value"; ?></a> at <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</li></ul>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
Which intends to display a list of a specific post type (stores) in the sidebar if a specific custom field is not empty. On single posts that works great - on the main page (home.php) it doesn't - the sidebar widget is empty.
I'm stumped. Any ideas?
John
$before_widget
or$after_widget
content, or is it only the list that is missing? Have you considered usingget_posts()
instead ofWP_Query()
andwp_reset_query()
, to prevent weird issues from overriding the main query?