Search
Close this search box.

WORDPRESS SQL语句查询

// 查询当前关键词总条数信息
$search_count = $wpdb->get_var($wpdb->prepare("select count(*) from wpt_posts as p LEFT JOIN wpt_users as u on p.post_author = u.ID where p.post_name like '%".$post_name."%' and p.post_status = 'publish'"));

// 查询当前关键词分页的数据
$sql = "select p.ID,p.post_author,u.user_nicename,p.post_content,p.post_title,p.post_name,p.post_status,p.post_modified,p.comment_count,p.post_date from wpt_posts as p LEFT JOIN wpt_users as u on p.post_author = u.ID where p.post_name like '%".$post_name."%' and p.post_status = 'publish' order by p.post_date desc limit ".$page." , ".$posts_per_page." ";
$res = $wpdb->get_results($sql);

发表评论

Optimized by WPJAM Basic