我正在尝试在按自定义字段“价格”排序的页面上获取帖子我已经完成了排序,但现在我无法得到“价格”的值。get_post_meta 不提供任何输出。这是代码:
$args=array(
'meta_key'=>'price',
'post_type' => 'page',
'orderby'=>'meta_value_num',
'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() ) {
$count=0;
while ($count<4 && $my_query->have_posts()) : $my_query->the_post(); ?>
<td><a href="<?php the_permalink(); ?>">
<img alt="product" src="/product-images/image.jpg" height="100px" width="75px"/>
<p><?php the_title(); ?></p>
<?php echo get_post_meta($my_query->ID, 'price', true); ?>
</a>
</td>
<?php
$count++;
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>