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
This is your code converted so it does not use global variables, and thus can’t stomp on anything. If this does not work, check your plugins: maybe one of them uses a hook in
WP_Query
to change the query on the home page?get_posts()
gets around that by settingsuppress_filters
totrue
, but I don’t know whether that disables all hooks.