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

Query posts by meta value and sort by another meta key

I am not sure what 'be_price' is for, but I think your $args should look like this:

$args = array(
    'post_status' => 'publish',
    'posts_per_page' => '150',
    'cat' => $cat_id, 
    'meta_key' => 'popularity',        
    'order' => 'DESC',
    'orderby' => 'meta_value_num',
    'meta_query' => array(
        'key'     => 'gone',
        'value'    => '1'
    )                     
);

Related Posts:

  1. order by numeric value for meta value
  2. What is the most efficient way of querying posts based on visits and date for current day?
  3. Query Custom Meta Value with Increment
  4. Pull post meta with post_query?
  5. WordPress query posts with multiple post_meta data
  6. WP_Query meta compare must include ALL array values
  7. Query against multiple locations within single custom post type post
  8. I need query_posts() to order results first by a meta value and then by post ID
  9. WP_Query with child element
  10. How to get several fields from wp_query?
  11. How to query post ids liked by the Author
  12. query by meta value then date and not empty meta value
  13. How to get posts that have certain meta key value and order based on another meta key’s value
  14. When should you use WP_Query vs query_posts() vs get_posts()?
  15. How to only display posts whose meta_value field is not empty?
  16. Can wp_query return posts meta in a single request?
  17. Wp get all the sub pages of the parent using wp query
  18. How do I query for posts by partial meta key?
  19. Return only Count from a wp_query request?
  20. Use REGEXP in WP_Query meta_query key
  21. How to query for most viewed posts and show top 5
  22. WordPress retrieving meta data for all custom post types in list view
  23. WP_Query vs get_posts
  24. Order by optional meta key?
  25. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  26. WP_Comment_Query pagination, delving into the unknown
  27. Usage of the new “posts_clauses” filter in WordPress 3.1?
  28. Reduce or prevent calling of update_meta_cache
  29. Make a WP Query search match exactly the search term
  30. WP_Query: query posts by ids from array?
  31. Is there a way to extend WP_query so Custom Post Types can have properties?
  32. Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
  33. Sort posts by category name and title
  34. How to uniquely identify queries?
  35. Custom WP_Query order by post_meta and (author) user_meta
  36. Query WooCommerce orders where meta data does not exist
  37. Getting attachments by meta value
  38. WP_Query for WooCommerce Products
  39. pre_get_posts with get_posts
  40. WP_Query displaying ALL posts
  41. meta_query where value is equal to given value
  42. author.php with ACF and CPTs
  43. WP-CLI How to generate a list of posts with corresponding meta values
  44. When should you use wp_reset_postdata vs wp_reset_query?
  45. Get posts by meta data OR title
  46. Identify which loop you are hooking into; primary or secondary?
  47. Perform query with meta_value date
  48. WP_Query ordered by custom field that is a date string?
  49. How to make an activities stream mixing posts and comments?
  50. Duplicate Queries
  51. How to query for a week using key => value WP_Query argument notation?
  52. Finding all results from database within 500 miles of the given latitude and longitude [closed]
  53. What is an efficient way to query based on post_meta?
  54. Show only oldest post by author
  55. Order posts by tags count?
  56. WP_Query not working as expected for attachments and custom meta_query
  57. SQL query equivalent to WP User Query
  58. Add and in the header while looping over custom query in page template
  59. How to get the posts published in last two days using WP_Query?
  60. How to count post meta key values for all posts in database
  61. Highlighting Sub topic in a post?
  62. Which custom query am I in and how can I access its properties & methods?
  63. How to count post type that has a particular term?
  64. Group posts by meta_key
  65. How should I use posts_where to change meta_value from a string to integer?
  66. Finding the next 5 posts
  67. How can I create a WP_Query that returns posts where one meta_value
  68. how to retrieve specific product attribute value in an sql query?
  69. WordPress altering my custom query, How to fix it?
  70. WP Meta Query for some meta (array) values
  71. WP Query post meta value
  72. Dynamically Override Fancy Title – Part II
  73. Would this post meta be better added to the post table rather than post_meta table
  74. Custom URl parameter
  75. Transient pagination not working properly
  76. query posts in functions.php and update a field
  77. Foreach-generated custom tax queries, each with an ajax “Load more” button
  78. Compile meta values from custom loop into array and then calculate sum total
  79. Can not switch the queried post in pre_get_posts hook
  80. How to get sum of meta_values of a meta_key in wp_query according to conditions
  81. how to fire join query with post_meta
  82. view queries made?
  83. Best approach to create Hot and Trending sections
  84. meta_query on a date range using an array of values
  85. WP_Query Performance Issues with meta_query
  86. WP_Query, custom sort and custom filter
  87. WordPress custom archive page
  88. How to speed up wp_query, took more 5s to run against 100k posts
  89. WP_query category__in not working, only pulls from first category
  90. How to detect custom query inside `posts_where` hook?
  91. Pass the same object to multiple widgets in a template with one query
  92. Is temporarily overwriting $wp_query a bad idea?
  93. Get the post permalink within the loop but without additional DB query
  94. Query Set Order By Author
  95. List the 5 most recent child pages
  96. Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
  97. Retrieve or Query Pages by ID
  98. Order posts by meta value and Date
  99. Efficient way to update multiple post meta
  100. How do you query wordpress posts using a math formula between multiple meta field values?
Categories wp-query Tags post-meta, query, wp-query
Custom contact info in user profile not displaying
Get Taxonomy and metadata

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