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 according to specific post meta values

Your syntax is complete wrong in your meta_query. A key/value pair in an array should be in the format of 'key' => 'value'. Your format is 'key', 'value' which in context of an array translate to 0 => 'key', 1 => 'value'. That is why your meta_query does not work.

Your failure is also due to not very good housekeeping. As your meta_query is written, it is hard to properly read it and because of that you miss obvious bugs.

Lets rewrite that section in a more readable way

$meta_query = [
    [
        'key'     => 'job_status',
        'value'   => 'open',
        'compare' => '!='
    ]
];
$query->set( 'meta_query', $meta_query );

As you can see, my code is easy to read, and very easy to spot obvious bug.

EDIT

If you need to add another key/value pair in your meta_query, you can simply just add another array.

$meta_query = [
    [
        'key'     => 'job_status',
        'value'   => 'open',
        'compare' => '!='
    ],
    [
        'key'     => 'another key',
        'value'   => 'another value',
        'compare' => '!='
    ]
];
$query->set( 'meta_query', $meta_query );

Related Posts:

  1. Order by meta value pro first then meta value free in my search function
  2. Search custom post type by meta data
  3. How to display liked posts of current user in wordpress?
  4. Filter query posts by the count of metas for a meta key
  5. Save default value for empty or missing post meta
  6. Grouping related postmeta data via SQL query
  7. mySQL query. ORDER BY meta_key
  8. Remove posts from query for events whose start date has passed
  9. Query metas (and not : query posts by metas)
  10. Issue with using add_rewrite_rule() for post querying custom fields
  11. get_post_meta with WP_query
  12. Declaring a var, placing it in a query and using the output of the query?
  13. Combining two meta_values within one row with query
  14. Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
  15. Sort by postmeta on when searching
  16. Use $wpdb->get_results with filter based on array
  17. What is the best way to query posts based on live data?
  18. Custom MySQL Query for Post and Post Meta
  19. How to display SQL query that ran in query?
  20. How to only display posts whose meta_value field is not empty?
  21. How can I create a meta_query with an array as meta_field?
  22. Query multiple meta key values?
  23. How to Optimize WP site for millions of posts
  24. order by numeric value for meta value
  25. How to get comments by post ID?
  26. Differences between wpdb->get_results() and wpdb->query()
  27. Is there a way of increasing the speed of this query?
  28. Get all image from single page using this query
  29. How can I query all users who registered today?
  30. Get Terms by IDs with IDs order
  31. Reversing the order of posts AFTER the query is performed
  32. what are the numbers between curly brackets in search query
  33. simple sql query on wp_postmeta very slow
  34. Using WordPress public query variables
  35. How to Use Wildcards in $wpdb Queries Using $wpdb->get_results & $wpdb->prepare?
  36. When/why does ‘$query->get( ‘tax_query’ );’ return empty?
  37. How to get link and title of next and previous post on single page
  38. Create pagination and order according to alphabet
  39. wpdb get posts by taxonomy SQL
  40. Dealing with Many Meta Values, 30+
  41. How to List Events by Year and Month Using Advanced Custom Fields?
  42. What is the most efficient way of querying posts based on visits and date for current day?
  43. Is there any difference between hooks posts_where with posts_join and posts_search performance wise?
  44. wordpress query – orderby child post date
  45. How many WordPress SQL Queries per page?
  46. How to display Section for certain time
  47. Add multiple value to a query variable in WordPress
  48. Custom query_var causes displaying posts archive on front page
  49. Slow wp_enqueue_media()
  50. Multipart/formatted MySQL query problem
  51. Custom Queries: Joining On Meta Values From Two Custom Post Types
  52. What is the most efficient way of implementing a favorite post system?
  53. Query Custom Meta Value with Increment
  54. Remove [gallery] shortcode altogether
  55. Compare two numeric custom fields
  56. wp_dropdown_categories with multiple select
  57. Advanced Custom Fields – Query Efficiency
  58. Why does get_the_time(‘F j’) return November 30 for all posts?
  59. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  60. Query by one meta_key and sort by another (possibly NULL value)
  61. How to tune search argument in WP_Query to show only exactly the same results?
  62. Custom query filter not working on woocommerce category page
  63. How to delete a transient on post/page publish?
  64. WPDB Multiple site’s posts and get featured images
  65. Very slow query
  66. query multiple taxonomy and show post count
  67. Search Terms – Querying on either description__like OR name__like in the same Term Query?
  68. Query & Sort Comments by custom comment meta
  69. How to get my loop to pull posts into three columns
  70. How to display lastest post date in the homepage?
  71. Custom $wpdb Query for Custom Post Type by Category
  72. WordPress Admin Panel search posts with custom post meta values along with title
  73. Get a user’s most recent post title
  74. Categories and products in random order
  75. add_query_arg() XSS Vulnerability
  76. Count user posts by user ID, Post type and Post status
  77. Can’t pass table to $wpdb->prepare
  78. Query set using tax_query with relation ‘OR’ modifies category object?
  79. $query->query_var[‘post_type’] not set for pages
  80. is_archive() doesn’t work on public query var archive pages?
  81. How to extract all ID variables from a query string?
  82. When add_query_arg() is necessary?
  83. Different Main Navigation per category
  84. How to get category link without a database query
  85. Insert html after certain amount of posts?
  86. wp remove query
  87. Show recent products first but “sold out last” in query
  88. How to break meta values into different items and avoid duplicates?
  89. WordPress creating excessive joins on meta_query with search
  90. How to tell if $query_var isset?
  91. Show All Posts Insert Edit Link
  92. $wpdb->get_var not returning a result
  93. search through post-type attachments titles
  94. How to count get_users query?
  95. Date query year and month OR just year
  96. cron job to auto delete posts of a specific post type older than x days
  97. Possible to get posts from multiple meta keys/values in a single query?
  98. Are database queries created using WordPress filters protected from SQL injection?
  99. Get IDs of posts currently visible on archive
  100. Get posts by category with pure SQL query
Categories query Tags meta-value, post-meta, query
Get new password without email
Featured image on post edit page not loading over HTTPS

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