admin管理员组文章数量:1122832
I want to fetch multiple posts with categories and tags currently I'm using this query:
$pagesize = 20;
$pageNumber = 1;
$mysql = mysqli_query($con,"SELECT p.post_title,
p.ID,
p.post_content,
p.post_date,
p.post_name as url,
t.name as category_name
FROM wp_posts p,
wp_terms t,
wp_term_relationships r,
wp_term_taxonomy tt
WHERE p.post_status='publish' AND
tt.taxonomy = 'post_tag' AND
p.id=r.object_id AND
r.term_taxonomy_id=tt.term_taxonomy_id AND
tt.term_id = t.term_id
ORDER BY p.post_date desc
LIMIT ".(int)($pageNumber*$pageSize).",".(int)$pageSize."") or die ("error".mysqli_error($con));
The mysqli-connection works. But when I run this code, I only get a blank page. How can I fix this?
I want to fetch multiple posts with categories and tags currently I'm using this query:
$pagesize = 20;
$pageNumber = 1;
$mysql = mysqli_query($con,"SELECT p.post_title,
p.ID,
p.post_content,
p.post_date,
p.post_name as url,
t.name as category_name
FROM wp_posts p,
wp_terms t,
wp_term_relationships r,
wp_term_taxonomy tt
WHERE p.post_status='publish' AND
tt.taxonomy = 'post_tag' AND
p.id=r.object_id AND
r.term_taxonomy_id=tt.term_taxonomy_id AND
tt.term_id = t.term_id
ORDER BY p.post_date desc
LIMIT ".(int)($pageNumber*$pageSize).",".(int)$pageSize."") or die ("error".mysqli_error($con));
The mysqli-connection works. But when I run this code, I only get a blank page. How can I fix this?
Share Improve this question edited Apr 26, 2017 at 11:08 Philipp 1,24213 silver badges19 bronze badges asked Apr 26, 2017 at 6:52 MohnishMohnish 112 bronze badges2 Answers
Reset to default 01) Blank page in WordPress means, there is a fatal PHP error in your code. Also the or die()
statement could cause the white page. You should not use or die()
in production code, instead use try .. catch
2) Besides this I strongly discourage you from using mysqli_* functions in WordPress. Always use $wpdb
for DB access!
3) Your query has some issues, but those will not cause the blank page but possibly incorrect results.
4) In this case you possibly want to use core WP functions instead. Like get_posts()
and get_the_category()
Turn on debug
(to true) it will allow you to see error.
本文标签: categoriesHow to run select query of post with category and tags
版权声明:本文标题:categories - How to run select query of post with category and tags? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287172a1927821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论