Use $wpdb->show_errors( true ) before the query and see what error comes back.
My problem (because I’ve experienced the same thing) was that I should use $wpdb->posts instead of wp_posts inside the query. The prefix of the tables can change from WP installation to installation or even in the same installation depending on the time (e.g. an admin can change the prefix whenever he likes). So, one should write the query like that:
$query = "select <stuff here> from $wpdb->posts where <stuff here>";
Related Posts:
- WPDB: how to get the value of a field in a custom database table
- Get stock by custom meta field on all Woocommerce variable products
- how to delete 30 day old data using PHP [closed]
- Display fields as values in array from external SQL DB
- Querying wpdb using PHP
- $wpdb->insert() does not Insert record in a table
- Use $wpdb or other PHP script method to find/replace in WP database
- How can I add a new row in a separate database when someone registers via WordPress?
- PHP -> SQL Query with Summing
- Why my query does not run with prepare
- wpdb getting avatars and author url
- WordPress SQL JOIN query
- Fetching review value using wpdb class
- Database SQL query error
- WordPress SQL Prepare
- Creating multiple tables with Plugin
- Querying multiple meta_keys in WordPress SQL query
- Can’t send form data to wpdb when URL has query string
- queries inside of a class
- How to Join two tables from separate databases within WordPress
- Would manually deleting the dumping data fix a “#1062 – Duplicate entry ‘1’ for key ‘PRIMARY'” phpMyAdmin error?
- Database “Migration” for Plugins?
- Automatically generate Post/Page from searched Database item?
- List of posts by day of the week
- register_activation_hook isn’t adding table to DB
- How to display posts of specific category using a custom Query in WordPress?
- What SQL / WordPress queries would need a nonce?
- Renaming post IDs – Okay to do?
- How to generate page content from database the right way?
- Converting MYSQL to WordPress $WPDB
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- phpMyAdmin displays error when importing database
- Preferred Method of debugging a wordpress SQL calls?
- Call External Object in Class Function During Callback
- Why is variable not working on custom sql query using wpdb?
- Trying to establish connection to External Database
- WSoD being caused by this piece of code
- $wpdb->update with multiple parameters gives error
- Update results, Before deleting the related category [closed]
- How WordPress reacts to a lack of memory of the server [closed]
- wp query foreach deleting record returning only first or last item
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Error using WordPress $wpdb object to get result from custom table
- How to retrieve the data from the sever and displaying it in a page?
- Querying Database with wpdb
- how to get serialized post meta
- How to Update post_modified of all wordpress post
- Basic wpdb update question
- wpdb Cannot Update column in Database
- Lost in trying to create user database system
- Pull MySQL data from multiple tables and merge into 1 PHP array
- Cannot access $wpdb, comes back NULL
- How do I prepare strings for insertions as values into a MySQL table?
- WPDB – Read and write value from / to database
- form $_post action value gets truncated after it passes through two forms
- How to Generate a list of Most Commented post?
- Why won’t this wpdb get_results query return results?
- Undefined variable: row?
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- making php value numeric
- Using color schemes with Color Picker
- populate select options from extra mysql table data
- quotes problem in very simple sql
- Add posts to custom table in database instead of wp_posts
- get_terms with specific id order
- get different meta-data of a complicated query at the same time
- Build A Custom SQL Query for WordPress Search
- How to run complex query using PHP
- Storing huge number of users in wordpress
- Custom User registration system
- How to use Multi SQL Database in WordPress?
- Conditional formatting on data fetched from MYSQL
- Using wpdb to connect to a different database is not working
- Looping through custom data in a custom table to display all items in a post
- Displaying SQL query result from user input via wpdb
- How do I create a WP endpoint that retrieves all custom post types that have a tag?
- How do I get data from my database into my Custom Export Field
- How to grab data from input and store it into custom table in database?
- Update user_email via php – WP 4.7
- Plugin Modification Change Functionality For Logged User Only
- direct query to post_meta table
- Unable to pass variable to database
- What to create new post using wp_insert_post, but it repeat the post infinitely
- Conditional statement within WP SQL query
- Passed variable gets undefined variable error on insert on next page
- Run insert if no entry otherwise run update with ajax
- See output of a sql query while plugin installation in wordpress
- How can I order metaboxes in my posts in WordPress?
- MySQL database migration to WordPress
- How do you get a reference to $wpdb in a PHP script
- WordPress Query -> Ajax Query
- how to display tables via ajax
- Changing regular db connection to $wpdb
- use wpdb object on other file
- $wpdb how to make a record lookup
- Error resetting database index using ALTER TABLE in $wpdb->query
- How to sort search result by post_title, then by post_content
- WordPress / PHP: Check if column has value and then check if value in array
- get_var not returning a value when the field contains an apostrophe