投票记录表
生成的sql语句: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语句应该怎样写呢?
解决办法:
使用wordpress的钩子函数,在发表文章的同时添加一条记录到投票表不就可以了?
直接上代码:
复制代码代码如下:
//发表文章的同时插入数据到喜欢表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里面。