Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How can I sort posts by the date and a custom meta field?

Basically, I am reading right out of the Codex page for WP_Query.

You want a meta_query similar to this with an orderby parameter with the two values you want to order by. The first is dominant.

$args = array(
    'post_type' => 'post',
    'meta_query' => array(
        array(
            'key' => 'rating',
            'value' => 3,
            'compare' => '>'
        )
    ),
    'orderby' => 'rating post_date',
    'order' => 'DESC'
);
$query = new WP_Query( $args );

I don’t know what your rating field is named and I don’t have your posts and your ratings on my system so I can’t test that. Hopefully that will get you started.

Related Posts:

  1. WP_Query sort by meta_value_num or date
  2. WP_Query orderby not working with meta_value_num and menu_order
  3. Creating Ordered Query using Meta_key
  4. How do I reorder (pop and push) items from WP_Query?
  5. Update all posts automatically when using post_meta
  6. Reverse chronology of post listing
  7. Better post meta efficiency?
  8. Change post format using custom field
  9. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  10. What Is meta_id In wp_postmeta?
  11. Add custom field automatically (add_post_meta) with value based on number of words of article
  12. Automatic value for custom fields for posts
  13. is there a way to show the the post title after the image?
  14. How do I correctly set up a WP-Query to only show upcoming event-posts?
  15. Query Posts With Over 1000 Views
  16. Cannot retrieve a custom RSS field from posts
  17. How to order posts by meta_value and title
  18. Query Posts by Custom Field
  19. how to get post order by post id wp_query?
  20. Customize rel=canonical tag for single blog post
  21. How to I retrieve the ID from the Posts page?
  22. Create a list of posts with topic headdings
  23. if in category but only with post meta
  24. wp_query with ajax
  25. Saving Post Data in Another Database
  26. Need to know custom code to display random and most viewed posts in wordpress posts and pages
  27. Add multiple meta keys to a post at once
  28. WP_Query custom field pass the post id
  29. saving/reading custom field value does not work – no value gets POSTed
  30. Override WordPress core post-template.php block template
  31. Post meta not working
  32. query posts with selected post ids first
  33. How do you update post date (year only) in a separate custom field?
  34. How to get value of a selected option from select tag and use it in WP_query to filter posts?
  35. How do I display posts ordered by a date custom field?
  36. Random order of the 5 most popular posts
  37. My custom query is displaying random posts in random order
  38. Get query result according to merged array
  39. Show posts between two Custom Fields date
  40. WP Query between posts custom fields [duplicate]
  41. Order posts by separate menu order for different sub-categories
  42. Order by ‘s’ using WP_Query()
  43. How enter custom post meta or custom field on box post list archive page?
  44. WP_query sort by custom meta_key “price”
  45. Image inside the content is replaced with featured image from my older post
  46. Should we trust the post globals?
  47. Order by optional meta key?
  48. Add a checkbox to post screen that adds a class to the title
  49. Export WordPress Posts and Meta Information in CSV format
  50. Querying post from a multisite network
  51. How to know if get_posts() failed?
  52. Show related posts by category but ignore one category
  53. HTML code in Custom field
  54. Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
  55. How to add padding between posts
  56. Working Bootstrap Carousel Conversion to WP – Technical Questions
  57. Add few specific post ids to wp_query
  58. How can I make existing custom fields easier to edit/add in my theme?
  59. WP_Query posts_per_page ignored
  60. wp_query ‘s’ parameter does not work with custom post type
  61. WP Query – duplicated posts once including tags in search results
  62. how to get posts ids inside pre_get_posts filter?
  63. Search by post title and content in wp_query without order
  64. Order Custom Post Type by Custom Field Value
  65. how to change the number of posts returned in a specific loop without making it global?
  66. Redirect to another page using contact form 7? [closed]
  67. How to automate featured posts number? [duplicate]
  68. Nested WP_Query breaking loop
  69. How to save meta checkbox WordPress
  70. Query for first 3 posts to change the look and feel
  71. Getting blog pagination to work on page set as front page
  72. unique post in “$args” of wp_query display more than one post
  73. Custom permalink for each post
  74. Is there a way getting post fields using `transition_post_status`
  75. Not all posts showing in query
  76. WordPress query portfolio posts
  77. Get latest author posts inside the loop
  78. Display 3 posts with different HTML markup using a loop
  79. Why my meta boxes won’t show in front post page?
  80. How to show multiple posts thumbnail, title and date in widget
  81. Only the most recent post is showing on my category page (working on localhost, not live site)
  82. Featured Images most often doesnt appear
  83. Manipulated offset and pagination, can’t display last post anymore
  84. How to display particular set of wordpress post on a webpage?
  85. Show 5 posts and than 3 posts offset with pagination
  86. Meta key in wp_query bug?
  87. Is it possible to query a category with specified posts?
  88. How to retrieve a post by inputing the url in a custom field and displaying it on an options page
  89. Sorting Posts with meta value not working
  90. Query to get data of a post, if in category?
  91. Order posts by custom field
  92. Ordering posts alphabetically by meta keys and title
  93. Remove duplicated posts in the loop if post has more than one category
  94. Why I getting only 1 post?
  95. 404 on Pages for Custom Post Type & Query_Posts
  96. get_post_meta property of non object
  97. First post in loop displays twice
  98. Site ‘Categories’: save an admin global setting with post metadata [closed]
  99. WP_Query sort by ACF date field (newest first) with blank dates first
  100. Is it possible to use the_post 2 times in one loop
Categories posts Tags custom-field, order, post-meta, posts, wp-query
Override theme style with other CSS on a specific page
get_post_type() and WP_QUERY issue

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress