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
- How to properly prepare a column name if passed to a stored procedure?
- Fatal error: Call to a member function query() on a non-object
- Custom array from a query only write the last row of the query
- Is it best to avoid using $wpdb for security issues?
- 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
- $wpdb returns duplicate posts
- Can’t update multiple rows with $wpdb query
- Mixing variables into an array when inserting values
- Wpdb->insert() doesn’t insert new row after the last one
- dynamic page using php from sql database
- how to get serialized post meta
- How to Update post_modified of all wordpress post
- Correct PHP to output a single result of a Function with SQL Query
- How to get specific attribute from DB
- Basic wpdb update question
- I can’t update my data through $wpdb
- wpdb Cannot Update column in Database
- Output: “Array”
- How to use mysql LIKE with wpdb?
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Lost in trying to create user database system
- Delete database record using plugin from admin panel
- Pull MySQL data from multiple tables and merge into 1 PHP array
- Cannot access $wpdb, comes back NULL
- Wpdb get->results to out the the month from the db
- How do I prepare strings for insertions as values into a MySQL table?
- Filter results from a serialized string to use on statistics
- wordpress site – using custom database and PHP
- How to use AJAX in WordPress in MYSQL query?
- Searching Posts Programmatically in a WordPress Plugin
- Use variable in SQL statement
- Change MySQL PDO connection to a WPDB connection
- WPDB – Read and write value from / to database
- $wpdb->get_results breaking page?
- 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?
- WPDB secure custom form
- mySQL queries are executed twice on wordpress website
- Undefined variable: row?
- Add row to custom database Table and delete all rows older than 1 day
- Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin
- 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
- Query the links Database
- Remove password protection from all posts
- quotes problem in very simple sql
- wordpress sql posts query won’t display the latest post in a specific category
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- WP_Query: How to get results from both meta_key options?
- MySQL Query Returns Array () In Shortcode
- WordPress get last inserted user id
- Add posts to custom table in database instead of wp_posts
- get_terms with specific id order
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- Passing in MySQL prepare statement parameter separately throwing error
- Convert a column of a table containing an Array as response in HTML
- 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
- add role on WordPress in PHP on a second database
- Trying to create a shortcode to display categories with a specific product tag
- Fetch Data from an external MSSQL Database in a Managed WP hosting
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- Custom User registration system
- How to use Multi SQL Database in WordPress?
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Conditional formatting on data fetched from MYSQL
- Woocommerce – get daily sales meta
- What is the correct way to search 3 custom fields only in WordPress?
- Using wpdb to connect to a different database is not working
- Running a PHP SQL script on a wordpress page
- Looping through custom data in a custom table to display all items in a post
- Displaying SQL query result from user input via wpdb
- Collect all events in one year
- WordPress search query, how to modify the sql
- How do I create a WP endpoint that retrieves all custom post types that have a tag?