admin管理员组文章数量:1130349
This works if I replace $wpdb->posts with the literal table name in the database, but not if I try to switch it over to $wpdb->posts. I thought this is used to solve the databases being named wpgh, wpbs, wphh, or any other combination of wp and some characters.
$results = $wpdb->get_results( 'SELECT * FROM $wpdb->posts WHERE post_type = "page" OR post_type = "post" AND post_status = "publish"');
Am I doing something wrong or is there another way to get the posts table?
This works if I replace $wpdb->posts with the literal table name in the database, but not if I try to switch it over to $wpdb->posts. I thought this is used to solve the databases being named wpgh, wpbs, wphh, or any other combination of wp and some characters.
$results = $wpdb->get_results( 'SELECT * FROM $wpdb->posts WHERE post_type = "page" OR post_type = "post" AND post_status = "publish"');
Am I doing something wrong or is there another way to get the posts table?
Share Improve this question edited Nov 24, 2018 at 7:24 butlerblog 5,1413 gold badges28 silver badges44 bronze badges asked Dec 11, 2016 at 18:22 Trevor ThorpeTrevor Thorpe 11 bronze badge 1- Your issue was single quotes, PHP variables only work inline inside double-quoted strings. – Rarst Commented Dec 11, 2016 at 19:47
1 Answer
Reset to default 0Turns out this works.
global $wpdb;
$postsTable = $wpdb->posts;
$results = $wpdb->get_results( 'SELECT * FROM '.$postsTable.' WHERE post_type = "page" OR post_type = "post" AND post_status = "publish"');
This works if I replace $wpdb->posts with the literal table name in the database, but not if I try to switch it over to $wpdb->posts. I thought this is used to solve the databases being named wpgh, wpbs, wphh, or any other combination of wp and some characters.
$results = $wpdb->get_results( 'SELECT * FROM $wpdb->posts WHERE post_type = "page" OR post_type = "post" AND post_status = "publish"');
Am I doing something wrong or is there another way to get the posts table?
This works if I replace $wpdb->posts with the literal table name in the database, but not if I try to switch it over to $wpdb->posts. I thought this is used to solve the databases being named wpgh, wpbs, wphh, or any other combination of wp and some characters.
$results = $wpdb->get_results( 'SELECT * FROM $wpdb->posts WHERE post_type = "page" OR post_type = "post" AND post_status = "publish"');
Am I doing something wrong or is there another way to get the posts table?
Share Improve this question edited Nov 24, 2018 at 7:24 butlerblog 5,1413 gold badges28 silver badges44 bronze badges asked Dec 11, 2016 at 18:22 Trevor ThorpeTrevor Thorpe 11 bronze badge 1- Your issue was single quotes, PHP variables only work inline inside double-quoted strings. – Rarst Commented Dec 11, 2016 at 19:47
1 Answer
Reset to default 0Turns out this works.
global $wpdb;
$postsTable = $wpdb->posts;
$results = $wpdb->get_results( 'SELECT * FROM '.$postsTable.' WHERE post_type = "page" OR post_type = "post" AND post_status = "publish"');
本文标签: mysqlWordPress Database Posts Table query
版权声明:本文标题:mysql - WordPress Database Posts Table query 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749154198a2324335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论