All you need to do is pass the field you want to order by in your SQL:
ORDER BY post_id DESC
This example will get the post_ids out with the highest first e.g. 99, 98, 97
OR
ORDER BY post_id ASC
will do it: 1, 2, 3 and so on.
Alternativly if you want to group the results by the meta_value:
GROUP BY meta_value
Related Posts:
- Querying Database with wpdb
- how to get serialized post meta
- $wpdb->insert() does not Insert record in a table
- Help with a $wpdb MySQL Query
- Fatal error: Call to a member function query() on a non-object
- Is it possible to retrieve all posts with a certain value for metadata?
- Get post id within comments loop
- Non-Closing PHP Query in WordPress Loop
- Custom array from a query only write the last row of the query
- 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?
- $wpdb returns duplicate posts
- Can’t update multiple rows with $wpdb query
- Mixing variables into an array when inserting values
- update_post_meta only updating on last loop of foreach
- Wpdb->insert() doesn’t insert new row after the last one
- How to use two meta_compare in an array?
- 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?
- How to get specific attribute from DB
- Basic wpdb update question
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress loop by meta key that is an array? and how loop multiple arrays
- I can’t update my data through $wpdb
- WordPress yoast seo plugin – parse snippet var in meta description
- wpdb Cannot Update column in Database
- Output: “Array”
- How to use mysql LIKE with wpdb?
- How to store multiple custom meta box
- PHP -> SQL Query with Summing
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Delete database record using plugin from admin panel
- Cannot access $wpdb, comes back NULL
- Wpdb get->results to out the the month from the db
- How to add post meta in while loop?
- Add category to post meta
- How do I prepare strings for insertions as values into a MySQL table?
- Using rules in Posts
- How to use AJAX in WordPress in MYSQL query?
- Update post meta – Custom field does not match meta-key
- Change MySQL PDO connection to a WPDB connection
- WPDB – Read and write value from / to database
- Order a WP_Query by meta value where the value is an array
- Save the value of a wp_dropdown_pages
- $wpdb->get_results breaking page?
- Add a custom class to the body tag using custom fields
- form $_post action value gets truncated after it passes through two forms
- Why my query does not run with prepare
- Define category ID using get_post_meta
- How to Generate a list of Most Commented post?
- Why won’t this wpdb get_results query return results?
- WPDB secure custom form
- Unable to Call More than One Meta Box Output
- wpdb getting avatars and author url
- Hide a div when a custom field is empty
- Undefined variable: row?
- Update value of a associative array with update_post_meta
- Add row to custom database Table and delete all rows older than 1 day
- Front end file upload returning wrong attachment url
- Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin
- Post meta select input, if statement
- select a single val though a table in wordpress
- WordPress SQL JOIN query
- populate select options from extra mysql table data
- Query the links Database
- Fetching review value using wpdb class
- WordPress stripping out custom field tags
- MySQL Query Returns Array () In Shortcode
- WordPress get last inserted user id
- How to check post meta isset or not empty during publish/save post?
- Add posts to custom table in database instead of wp_posts
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- get value from get_post_meta then reuse it in another get_post_meta
- Passing in MySQL prepare statement parameter separately throwing error
- Convert a column of a table containing an Array as response in HTML
- Order category posts by last word of custom field
- Database SQL query error
- WordPress SQL Prepare
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Loop for recently (updated_post_meta) posts?
- How to add and subtract user meta values after post meta update
- How to update custom fields when post is published?
- Update Images after edit via php
- Creating multiple tables with Plugin
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- No more get_option(‘date_time’) in WordPress 5.5?
- Conditional formatting on data fetched from MYSQL
- Delete post meta by serialized meta value
- Using zip code to display custom data in Admin Order Details
- What is the correct way to search 3 custom fields only in WordPress?
- Using wpdb to connect to a different database is not working
- Show a text if the post has written by author user role in WordPress
- Looping through custom data in a custom table to display all items in a post
- Hide author from search results meta, still display date and categories
- Fix common misspellings/errors based on array of replacements
- Displaying SQL query result from user input via wpdb
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- How do I create a WP endpoint that retrieves all custom post types that have a tag?
- Modify post image in full size
- Unable to update the meta boxes with multiple fields