我正在尝试显示上周最受欢迎的帖子。然而,我认为它工作不正常,显示了最受欢迎(浏览量最大)的帖子。我知道我的代码是有效的,因为我可以使用monthnum“=>$month查看上个月最受欢迎的帖子。如何修复此问题以显示上周最受欢迎的帖子?
<?php
$week = date(\'W\');
$year = date(\'Y\');
$new_query = new WP_Query( array(\'posts_per_page\' => 1, \'cat\' => 14, \'meta_key\' => \'wpb_post_views_count\', \'orderby\' => \'meta_value_num\', \'order\' => \'DESC\',\'weeknummer\'=>$week,\'year\'=>$year ));
?>
<?php if ( $new_query->have_posts() ) : ?>
<?php while ( $new_query->have_posts() ) : $new_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; wp_reset_postdata(); ?>
<?php else : ?>
<?php endif; ?>
// Popular Posts
function wpb_set_post_views($postID) {
$count_key = \'wpb_post_views_count\';
$count = get_post_meta($postID, $count_key, true);
if($count==\'\'){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, 0);
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
//To keep the count accurate, lets get rid of prefetching
remove_action( \'wp_head\', \'adjacent_posts_rel_link_wp_head\', 10, 0);
function wpb_track_post_views ($post_id) {
if ( !is_single() ) return;
if ( empty ( $post_id) ) {
global $post;
$post_id = $post->ID;
}
wpb_set_post_views($post_id);
}
add_action( \'wp_head\', \'wpb_track_post_views\');