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
- How to return number of found rows from SELECT query
- Can i use php sql functions instead of $wpdb?
- wpdb::prepare was called incorrectly
- Custom query to get post names beginning with a digit
- How to update single value in multi dimensional Post Meta?
- How to display only first value of database column in WordPress
- Print out WordPress user ID – two sites with same code but different output
- How can update custom meta for all posts
- WPDB: how to get the value of a field in a custom database table
- Can’t use get_results() in ajax query
- PHP syntax error when using wpdb update?
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- WordPress get pagination on wpdb get_results
- how to increase custom post value by one most efficiently?
- How to Display Image Meta underneath EVERY image in EVERY post
- Show MySQL errors that occur when I excute $wpdb->insert()
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Get stock by custom meta field on all Woocommerce variable products
- Any possible way to make $wpdb->get_results() return anything else than array?
- how to delete 30 day old data using PHP [closed]
- Echo a hierarchical list of post data from custom fields
- Display fields as values in array from external SQL DB
- The text box have space character
- Getting id of poll from WP database
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- I want to select the from values from database in WordPress? [closed]
- Sort custom meta column by other meta value
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- Querying wpdb using PHP
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Need help with Google drive API [closed]
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- Archive post by meta value + 24hours
- 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
- $wpdb returns duplicate posts
- Wpdb->insert() doesn’t insert new row after the last one
- 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
- WordPress loop by meta key that is an array? and how loop multiple arrays
- 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?
- Add category to post meta
- 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->get_results breaking page?
- Define category ID using get_post_meta
- WPDB secure custom form
- Unable to Call More than One Meta Box Output
- Hide a div when a custom field is empty
- Update value of a associative array with update_post_meta
- 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
- Query the links Database
- WordPress stripping out custom field tags
- WordPress get last inserted user id
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- Passing in MySQL prepare statement parameter separately throwing error
- Order category posts by last word of custom field
- WordPress SQL Prepare
- How to update custom fields when post is published?
- Delete post meta by serialized meta value
- What is the correct way to search 3 custom fields only in WordPress?
- Show a text if the post has written by author user role in WordPress
- Hide author from search results meta, still display date and categories
- Fix common misspellings/errors based on array of replacements
- Unable to update the meta boxes with multiple fields
- 403 Forbidden WordPress Database Results
- Reverse Cross-Sells (WooCommerce)
- Remove item from post_meta array via AJAX
- Rewrite SQL query as a prepared statement and use in foreach loop
- How to return count of items found in SQL query
- Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING
- Post from front end form to post_meta
- MySQL queries in WordPress
- At what point during a typical request does the $wpdb object become available?
- retrieve wordpress post-meta using php not wordpress functions
- Postmeta not saving
- If custom field doesn’t exist, or exists and it’s true show title?
- Get null from POST
- get_post_meta no longer working
- Fetching wpdb data from a php file seems to break?
- Metadata on the WP_Post object
- Insert into db with foreach problem
- posts_clauses drop ACF get_field function
- WordPress Query -> Ajax Query
- how to display tables via ajax
- inner-wrap div pushing custom table far down on page
- use wpdb object on other file
- How do I get a function to work in single.php
- Warning: Undefined property: wpdb::$question_overview in C:\Wamp.NET\sites\proxyvragenmodule\wordpress\wp-includes\class-wpdb.php
- WordPress / PHP: Check if column has value and then check if value in array
- How to modify default tags in wp_head()