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
- Transaction when using WP functions rather than vanilla SQL?
- Can i use php sql functions instead of $wpdb?
- wpdb::prepare was called incorrectly
- Display data from a non wordpress database on a page template
- How to get the list of WooCommerce product image of a certain category from database?
- Custom query to get post names beginning with a digit
- Alter query on edit.php
- How to auto login user again after change user_login
- count number of user comments with a specific comment meta value
- Print out WordPress user ID – two sites with same code but different output
- Can’t use get_results() in ajax query
- PHP syntax error when using wpdb update?
- my function doesn’t return my post from today
- Enhanced WordPress Search
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- WordPress get pagination on wpdb get_results
- Ajax $wpdb not returning table data
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Any possible way to make $wpdb->get_results() return anything else than array?
- Transferring working local PHP site to wordpress – with database (MySQL)
- Can’t get wp_insert_post to work
- Getting id of poll from WP database
- How to insert a single row to WP database table?
- I want to select the from values from database in WordPress? [closed]
- Importing Geo data into wordpress database
- Detect session/cookie variable in wordpress to prevent access to documents
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Database query works fine outside WordPress
- Help with a $wpdb MySQL Query
- Custom array from a query only write the last row of the query
- Querying Database with wpdb
- Wpdb->insert() doesn’t insert new row after the last one
- How to get specific attribute from DB
- wpdb Cannot Update column in Database
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- How do I prepare strings for insertions as values into a MySQL table?
- Change MySQL PDO connection to a WPDB connection
- WPDB – Read and write value from / to database
- $wpdb->get_results breaking page?
- 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
- Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin
- Remove password protection from all posts
- 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
- WordPress get last inserted user id
- 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
- What is the correct way to search 3 custom fields only in WordPress?
- 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
- Collect all events in one year
- 403 Forbidden WordPress Database Results
- Rewrite SQL query as a prepared statement and use in foreach loop
- How to return count of items found in SQL query
- Getting error in sql query
- user update profile for custom code
- Where to check in PHPmyAdmin / SQL database for subdomain
- Front end/Database connection in WP
- Plugin Modification Change Functionality For Logged User Only
- SQL Query Search page
- Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING
- Conditional statement within WP SQL query
- Run insert if no entry otherwise run update with ajax
- Can not manually create a database ( db, user, pass ) for a plugin
- MySQL queries in WordPress
- How to merge 2 WordPress sites?
- Get null from POST
- How to export database correctly for local to online
- MySQL database migration to WordPress
- Fetching wpdb data from a php file seems to break?
- Insert into db with foreach problem
- How to display inputted data in Ajax without button or click event
- inner-wrap div pushing custom table far down on page
- How to get data (not value or name) from radio options to POST to database
- I have an error WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version
- SQL query to retrieve the number of WordPress posts with all given categories
- Putting form result in my database
- SQL – How to echo out inside of where statement
- How can I update a value of a field depending on outside source?