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

Order by a meta field in query loop

<?php
$cat = get_post_meta( get_the_ID(), 'cat_page', true );

$args = array(
    'category_name' => $cat,
    'meta_key' => 'niveau_chiffre',
    'orderby' => 'meta_value_num', //Since we're dealing with numbers
    'order' => 'ASC',
    //'meta_query' => array(
       // array(
           //'key' => 'niveau-chiffre',
           //'value' => 'niveau-chiffre', Don't give a value because we're not looking for a specific one
           //'compare' => '>=', We're not comparing as such. Defaults to =
           //'type' => 'NUMERIC'
        //)
    ), //You missed a comma here I think
);

Try this.

Related Posts:

  1. Orderby meta_value only returns posts that have existing meta_key
  2. Auto sort the wp-admin post list by a meta key
  3. Limit the number of acf content when displaying in post loop [closed]
  4. Can I access a post meta field before the loop?
  5. wordpress custom loop ascending descending posts by custom field
  6. change order of images attached to post
  7. Filter or order based on custom field
  8. Compare ACF date field (if exists) and post date and order DESC
  9. Get meta value when the page is a blog archive
  10. Can I exclude a post by meta key using pre_get_posts function?
  11. Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
  12. Custom post meta field effect on the performance on the post
  13. How to get custom post meta using REST API
  14. Difference between meta keys with _ and without _ [duplicate]
  15. What is the index [0] for on post meta fields?
  16. What is “meta_input” parameter in wp_insert_post() used for?
  17. How to enable revisions for post meta data?
  18. The “_encloseme” Meta-Key Conundrum
  19. ORDER BY custom field value
  20. Best way to programmatically remove a category/term from a post
  21. Using get_post_meta with new_to_publish
  22. Custom field metabox not showing in back-end
  23. So much data in postmeta
  24. Can I count the number of users matching a value in a multiple value key?
  25. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  26. How to hide meta box values from custom fields list?
  27. get_post_meta() unserialize issue – returns boolean(false)
  28. What is the advantage of the wp_options design pattern?
  29. Storing meta fields multiple times OR once with multi dimensional array?
  30. Allow user to create instances of custom field
  31. display specific custom fields
  32. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  33. get_pages sort alphabetically by meta value
  34. Meta keywords and descriptions plugin for manually editing meta for each page/post
  35. passing argument to get_template_part() or a better way to code
  36. Is it possible to store arrays in a custom field?
  37. Archive sorting functions by custom fields (front-end)
  38. Get updated meta data after save_post hook
  39. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  40. Save HTML formatted data to post meta using add_post_meta()
  41. importing data from non-wordpress mysql db
  42. Order by custom field date?
  43. Order posts by custom field and if custom field is empty return remaining posts
  44. Is it possible to sort the post based on a custom field?
  45. Create meta boxes that don’t show in custom fields
  46. Transients vs CRON +Custom Fields: Caching Data Per Post
  47. Unable to save datetime custom meta field using update_post_meta() function
  48. Up/Down voting system for WordPress
  49. post meta data clearing on autosave
  50. Create custom field on post draft or publish?
  51. Display info from custom fields in all images’ HTML
  52. Ordering posts by anniversary using only day and month
  53. Calling Specific Pages with wp query Part II
  54. Loop through two different sets of custom fields
  55. get_post_meta fields don’t show up on posts page
  56. Update meta values with AJAX
  57. How to break meta values into different items and avoid duplicates?
  58. copy attachments to another post type and change attachment url
  59. Cannot edit post meta fields with rest API
  60. ajax delete value from custom field array
  61. Save attachment custom fields on front end
  62. How can I sort get_users() by any value (last_name, user defined fields and more)
  63. How to use pagination with get_post_meta
  64. Copying Custom Meta Values from existing post to a duplicate post
  65. Add a post meta key and value only if it does not exist on the post
  66. Move value of one custom field to another
  67. Order posts according to user defined order for meta values?
  68. Is it possible to order posts by two meta values?
  69. Displaying posts with only upcoming dates according their custom field date value
  70. Custom fields to save multiple values
  71. Custom fields: In what order are they saved into the DB?
  72. Function to change meta value in database for each post
  73. Get a post_id where meta_value equals something in a serialized meta_value field
  74. Get aggregate list of all custom fields for entire blog
  75. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  76. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  77. Sorting posts by multiple values, combined
  78. Custom field value based on other custom field values
  79. Sort by posts that have a featured image?
  80. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  81. How to save a ToggleControl value in a meta field?
  82. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  83. Saving custom image meta fields
  84. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  85. How do I exclude posts by custom field value?
  86. Echo values from custom field outside loop php
  87. How to display Meta Field Value?
  88. MySQL query to set wp_postmeta using term_taxonomy_id value
  89. How to Validate Post Meta type/extension (Video File Image File etc)
  90. Get all meta keys assigned to a post type
  91. Create a random unique 6 digit number as custom field for custom post type
  92. Upcoming Event: How do I sort database by custom date field, but ignore past dates?
  93. Calling custom fields for pages (not posts)
  94. Duplicate posts being displayed when querying Custom Fields
  95. using multiple meta_key and meta_value in query_posts
  96. Custom Meta Box not Saving in Posts with Gutenberg Editor
  97. sort search results by custom fields using dropdown
  98. Adding custom fields (post meta) before/during wp_insert_post()
  99. Combine multiple custom field values into single value
  100. How can I sort homepage by a meta value?
Categories custom-field Tags custom-field, loop, post-meta, sort
WordPress Post Content Display
How to create load more button without a plugin?

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