这为每个帖子提供了相同的视图值,我如何为每个帖子获取下一个var?
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?>
<?php
// set the meta_key to the appropriate custom field meta key
$meta_key = \'views\';
$views = $wpdb->get_var( $wpdb->prepare(
"
SELECT meta_value
FROM $wpdb->postmeta
WHERE meta_key = %s
",
$meta_key
) );
echo "<p>Total views {$views}</p>";
?>
<?php endwhile; ?>