SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_wti_like_post on wp_wti_like_post.post_id=wp_posts.ID WHERE 1=1 AND ( ( post_date_gmt > ’2013-11-16 12:17:03′ ) ) AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’) ORDER BY wp_wti_like_post.value DESC,wp_posts.post_date DESC LIMIT 5, 5
sql語句應(yīng)該怎樣寫呢?
//發(fā)表文章的同時(shí)插入數(shù)據(jù)到喜歡表
function new_article($post_ID){ global $wpdb; $ip = WtiGetRealIpAddress(); $query = "INSERT INTO {$wpdb->prefix}wti_like_post SET "; $query .= "post_id = '" . $post_ID . "', "; $query .= "value = '0', "; $query .= "date_time = '" . date('Y-m-d H:i:s') . "', "; $query .= "ip = '$ip'"; $success = $wpdb->query($query); if($success){ return $post_ID; }}add_action('publish_post', 'new_article');
把這段代碼放到主題function.php里面。 版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: wordpress鉤子函數(shù)在發(fā)表文章的同時(shí)添加一條記錄的方法