$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>mysql - WordPress Database Posts Table query|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

mysql - WordPress Database Posts Table query

matteradmin7PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

Turns 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"');

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far