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. Order by Post Title in WP Query not working
  47. How to bulk Update URLs to new values?
  48. Select another post in a post meta like a parent page is selected while editing a page
  49. SQL DELETE multiple post_meta on single and multi-sites
  50. Change Old WordPress Post Date Year
  51. How to create loop of posts except post ID defined via ACF field
  52. Displaying all posts from other sites on the network on one site
  53. the wp_post_update isn’t working all the time
  54. Trouble with serialized metadata
  55. Function is printing twice – any suggestions?
  56. Query on a repeater date (acf)
  57. Adding an option to post editor to show a site disclaimer or message
  58. Display/Filter post using if else statement
  59. How to sort WP_Post Object array by object field in php?
  60. Search results for ACF data
  61. Multisite how to display merged posts from two sites and sort by latest date?
  62. Saving canvas generated image when saving post causes 404 error
  63. Query prints posts without specific categories
  64. Private post caught in endless redirect loop
  65. Show posts from WP Custom Post Type selected from a field in a metabox
  66. How to retrieve all meta data directly from the $post object? Such as $post->related_topics?
  67. What is proper filter or hook action to add data to the $post object?
  68. Display specific posts based on an ID of another post
  69. SEARCH QUERIES – REVERSE OUTPUT
  70. Numbered Pagination Showing The Same Posts After Altering WP_Query
  71. Order by meta_key field in WordPress not meta_value field value
  72. a WordPress connected to 2 database
  73. How to display particular set of wordpress post on a webpage?
  74. Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
  75. Change URL of previous posts and next posts link in WordPress
  76. Query against multiple locations within single custom post type post
  77. Custom meta fields not showing up in WP_Response Object via custom endpoint
  78. How to invoke a HTML custom button based on a HTML dropdownlist menu
  79. How to create page with post content in it?
  80. Blogposting Schema & Structured Data without plugin
  81. Order posts inside bootstrap card columns
  82. long-title posts do not want published
  83. Automatically select template based on query string for New Posts
  84. How to remove a post from results by ID after query?
  85. Using a meta_value or postdate to to query and orderby
  86. Exclude posts in home slider from sections
  87. Display Updated Date Instead of Published Date
  88. Order 2 meta_queries differently in WP_Query?
  89. Is there a way to save different data when USER interacts with the same POST?
  90. Mix post date with post meta value using WP_Query
  91. How to use two query result together in one loop
  92. Add postmeta to all blog posts
  93. show loop id post , only first id can read
  94. When working with a post, almost all wp_postmeta are deleted
  95. WP_Query that targets all categories
  96. Counting Posts by Category
  97. Fill the exclude array() in get_posts()
  98. show image gallery in archives or category page
  99. Page with Category Returning 1
  100. The first post appears twice
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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