0
カテゴリのトレンドポストを表示しようとしています。私は1つの投稿を表示したいだけです。私はトレンドを今のトレンドと定義します。例えばカテゴリのトレンドポストを表示
:1K日ビューの周り
ポストAは100日齢で、合計10万のビューを持っていました。
ポストBは10日齢で、10Kビュー、最終日に8Kビューでした。
Aは長らく普及していますが、Bはこの時点で傾向があります(それ以前はAよりも日常的にトラフィックが少なくて済みました)。
<?php
$today = getdate();
$args = array(
'meta_key' => 'post_views',
'meta_value' => '1000',
'meta_compare' => '>=',
'orderby' => 'meta_value_num',
'ignore_sticky_posts' => 1,
'cat' => 14,
'numberposts' => 1,
'paged' => $paged,
'date_query' => array(
array(
'year' => $today['year'],
'month' => $today['mon'],
'day' => $today['mday'],
),
),
);
$trenquery = new WP_Query($args);
// The Loop
if ($trenquery->have_posts()) {
get_the_title();
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
のfunctions.php
// 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');
これは機能しませんでした。投稿は表示されません。 – user6738171
あなたのポストはポストビューのカウント機能を持っています。データベース全体を検索するには "post_views_count"というキーワードをチェックしてください。もしこのメタがあなたのwp_postmetaテーブルを持っていれば、それだけが動作します。 – GNANA
私はこの機能を自分の質問に追加しました。この機能を使用しても、それはまだ機能しません。 – user6738171