我现在有这个问题
global $wpdb;
$interval = "1 WEEK";
$now = current_time('mysql');
$top4=$wpdb->get_results('SELECT ID, post_title, post_name from `'.$wpdb->prefix.'popularpostssummary`
INNER JOIN `'.$wpdb->prefix.'posts` ON `postid`=`ID`
ORDER BY `pageviews` DESC
LIMIT 4;', ARRAY_A);
我想添加以下条件,在代码中添加它们的正确方法是什么?
WHERE post_type = post
AND last_viewed > DATE_SUB('{$now}', INTERVAL {$interval})
post_type位于'。$ wpdb->前缀。'帖子
while last_viewed is under '.$wpdb->prefix.'popularpostssummary
答案 0 :(得分:1)
global $wpdb;
$interval = "1 WEEK";
$now = current_time('mysql');
$sql =
'SELECT p.ID, p.post_title, p.post_name
FROM `' . $wpdb->prefix . 'popularpostssummary` AS pps
INNER JOIN `' . $wpdb->prefix . 'posts` AS p ON pps.`postid`= p.`ID`
WHERE p.post_type = "post"
AND pps.last_viewed > DATE_SUB("' . $now . '", INTERVAL ' . $interval . ')
ORDER BY pps.`pageviews` DESC
LIMIT 4;';
echo $sql; exit;
$top4 = $wpdb->get_results( $sql, ARRAY_A );