Thank you to Tom J Nowell for pointing me to using WP_Query
instead of get_posts
. With WP_Query you have the entire WP_Query
object to reference. So something like the following gives the actual mysql query of the args I was using.
// these same args also worked with get_posts()
$args = array(
'post_type' => 'post',
'order' => 'ASC',
'post_status' => 'publish',
);
// create a new WP_Query object with the args above
$the_object = new WP_Query($args);
// show the mysql as a string
echo $the_object->request;
// see EVERYTHING in the WP_Query object
var_dump($the_object);
Related Posts:
- Multipart/formatted MySQL query problem
- Are database queries created using WordPress filters protected from SQL injection?
- how to insert missing tags into the posts through mySQL?
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- SQL query to delete users with multiple meta keys and comments
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- How to make MySQL search queries with quotes
- How to display SQL query that ran in query?
- What SQL Query to do a simple find and replace
- Is there a way to list all used/unused WP templates?
- simple sql query on wp_postmeta very slow
- How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
- wpdb get posts by taxonomy SQL
- How many WordPress SQL Queries per page?
- Very slow query
- SQL query equivalent to WP User Query
- WordPress creating excessive joins on meta_query with search
- cron job to auto delete posts of a specific post type older than x days
- Get posts by category with pure SQL query
- Custom query to get terms from post ids
- Query WordPress database by registered date and role
- Get the timout value of a saved transient?
- Grouping related postmeta data via SQL query
- Does meta_query work within get_posts array?
- Mysql / WordPress killing my server with 80k users [closed]
- Slow meta_query with about 4 milion record on wp_postmeta
- How to show more than 5 posts?
- How to optimize my query filtering out unwanted data?
- mySQL query. ORDER BY meta_key
- Remove posts from query for events whose start date has passed
- get_posts() loop returns the same the_title() for each post
- Update slug (URL) of pending posts via phpMyAdmin
- My SQL function to change user_name
- What’s wrong with my $wpdb prepare?
- MySQL variable in query
- List all posts from past week grouped by sub-category
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Help with MySQL to $WPDB query
- SQL query to select posts from multiple categories
- Order posts by custom field DATE value
- Alter query with posts_clauses to retrieve NULL values last
- Order by summing multiple values
- sql select query in wordpress ‘page’ [closed]
- Create Indexes for Slow Queries
- problem with sql query in wordpress plugin
- MySql Query very slow
- Attempt to improve WP search, can someone check my SQL query?
- Searching With Apostrophe
- wpdb query problem to access previous 3 days posts
- WordPress Query wp-terms SLOW
- I can’t figure out what’s wrong with this statement. $wpdb->query update
- Making a query to the DB using same parameters of loop
- wpdb COALESCE won’t work
- get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)
- pre saved posts query from db options table
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Get posts from category with custom query
- SQL query to set posts in bulk based on the post content
- Valid SQL query return empty
- mysql query – how to escape apostrophe?
- exclude pingbacks from wordpress SQL query
- Optimize slow SQL query for multiple meta values
- prepare function sql safe method
- Re-sort get_posts query results
- WordPress SQL query to tag all posts containing a specific word on title
- mySQL queries are executed twice on wordpress website
- How to return count of custom post type posts with a specific custom field value via $wpdb?
- Select column name dynamically mySQL Query
- WordPress Mysql query and Duplicate
- How do I query for posts by custom meta and those that have been stickied?
- Help with Related Posts Function
- Can I include get_posts in this array?
- Change pure SQL database query to WordPress post query?
- How to delete all images from code in all post_content
- Cannot get sql request from Query object?
- Display data from phpMyAdmin with WordPress
- How can I get posts by 2 meta keys, prioritising one of them?
- Delete oldest wordpress post (SQL query)
- Displaying data from custom table
- Get 2 meta values from meta key column
- PHP Fatal error: Uncaught Error: Call to a member function insert() on null
- Nested select statements not working
- OR condition not working
- Speed up search query that searches in post meta?
- Category_in return empty
- Fastest and most efficient SQL query to check if UID exists
- Performance of wp_get_attachment_image_srcset() and wp_get_attachment_image_url()
- How i make a custom sql query for Woocommerce
- Run an update query in a function
- Custom MySQL Query for Post and Post Meta
- Sort order in get_posts [closed]
- Slow query when joining wp_posts with a lookup-table?
- Wpdb generates too many queries
- Mysql query and odd results
- learn to run wpdb class
- sql for querying post and their category
- Access Tables with number prefix
- SQL Query : how copy all tags of post into their post content in wordpress by sql query
- Custom Query for wp_posts using wp_postmeta
- 3 queries to update WordPress