いつもお世話になっております。WordPress初心者でございます。
下記サイトを参考にランキングを自作で作成しておりましたが、別方法で作成することになり、その別方法だとうまくランキングが機能せず困っております。
http://11neko.com/wordpress-tips/
DBに閲覧数を保持する専用のテーブルを作成し、ランキング機能のコードを書いていますが、その専用のテーブルの中身が空の状態のようで、phpMyAdminで確認しますと「返り値が空でした」とメッセージが出ています。
まず、該当のソースコードを確認していただけたら分かるかと思いますが、どのような意味なのかがまず理解できておりません…。
どこの部分を修正したらいいのか分からないので行き詰まっております…。
説明不足な点もあるかと思います。
お力添えいただければ幸いです。
###該当のソースコード
function log($post_id){ global $wpdb; $tname = self::table(); $post = $wpdb->query($wpdb->prepare("select ID from {$wpdb->posts} where ID=%d and post_status='publish'", array($post_id))); if($post){ $data = array( "post_id" => $post_id, "at" => time(), "ip_addr" => htmlspecialchars($_SERVER["REMOTE_ADDR"]) ); $wpdb->insert($tname, $data); } if(mt_rand(0, 1000) === 0){ self::delete_old_logs(); } } function ranking($days=30,$d=5,$post_type="post"){ global $wpdb; $tname = self::table(); $lower_limit = time() - 60 * 60 * 24 * $days; $sql = "select {$tname}.post_id from {$tname} " . "join {$wpdb->posts} on {$tname}.post_id = {$wpdb->posts}.ID " . "where at > {$lower_limit} and {$wpdb->posts}.post_status = 'publish' and {$wpdb->posts}.post_type = '{$post_type}' " . "group by {$tname}.post_id order by count({$tname}.post_id) desc"; $results = $wpdb->get_results($sql); return array_slice(array_map(function($obj){return intval($obj->post_id);}, $results),0,$d); }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/08/17 12:15
退会済みユーザー
2017/08/17 12:46
退会済みユーザー
2017/08/17 14:01
退会済みユーザー
2017/08/17 14:33
退会済みユーザー
2017/08/18 03:09