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 to use two meta_compare in an array?

Ok so this way is a bit long but it will get the job done.

We can use multiple meta_value checks with AND relation

// get posts
$posts = get_posts(array(
    'post_type'      => 'post',
    'posts_per_page' => 150,
    'meta_query'     => array(
        'relation' => 'AND',
        array(
            'key'     => 'usp-custom-1',
            'value'   => 'question',
            'compare' => '!=',
        ),
        array(
            'key'     => 'usp-custom-1',
            'value'   => 'money',
            'compare' => '!=',
        ),
        array(
            'key'     => 'usp-custom-1',
            'value'   => 'health',
            'compare' => '!=',
        ),
        array(
            'key'     => 'usp-custom-1',
            'value'   => 'relationships',
            'compare' => '!=',
        ),
    ),
    'author' =>  $_GET["id"],
    'order'  => 'DESC'
));

You need to check the performance hit for this query because it can be resouce heavy.

I alos noticed $_GET["id"], you passed it raw, I would suggest sanitizing/validating every value that was passed to you (values that you did not pass yourself, like user input or url queries).

By the property name I assume that it will be a id, so we can sanitize it like this

'author' => filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT)

Related Posts:

  1. How can merge two arrays values in one array and save in database
  2. How to update single value in multi dimensional Post Meta?
  3. Compare two meta key values against each other inside the get_posts array?
  4. Remove empty terms from array, sort alphabetically, update back to repeating field
  5. WordPress loop by meta key that is an array? and how loop multiple arrays
  6. Order a WP_Query by meta value where the value is an array
  7. Update value of a associative array with update_post_meta
  8. WP post meta – for loop inside for loop
  9. Remove item from post_meta array via AJAX
  10. How to update custom fields using the wp_insert_post() function?
  11. Get meta_id along with meta_key and meta_value
  12. Sorting list of sites from multisite network using wp_get_sites
  13. How to store the_title() into a variable to reutrn the value, not just echo it
  14. Metabox repeating fields – radio buttons not saving correctly
  15. Check if user already visited this post today
  16. Display all meta for a post?
  17. How to display multiple Post meta_key/meta_values by SQL query
  18. the_post_thumbnail() based on the Post ID
  19. How to use multiple query with same meta key
  20. Error in WP_update_post
  21. Why is my get_post_meta always empty
  22. How can update custom meta for all posts
  23. Looping through WP_Post Object
  24. Need to get specific data from array
  25. Using a javascript file to access a get posts array
  26. Create an array from an array
  27. WP_User_Query order by meta_key that is an array
  28. Use ajax to update_post_meta
  29. Generate an array of parent/child page IDs, based on parent page name
  30. How do I output a database option that is an array into a get_posts array?
  31. Can an array be used as a meta_query value?
  32. Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
  33. How do I dynamically generate args for wp_query?
  34. List of posts by day of the week
  35. Check if term object is in array
  36. how to increase custom post value by one most efficiently?
  37. Batch update a post meta field value of each post in Post Type
  38. Must Use Plugin Causing Query Error
  39. How to Display Image Meta underneath EVERY image in EVERY post
  40. ‘orderby’ => ‘rand’ alternative for better performance?
  41. How to convert objects into arrays
  42. Change description on specific WooCommerce product status change
  43. Parsing php string in jquery [closed]
  44. Admin Options page. Save as Array
  45. Use WP_Query in shortcode
  46. PHP get the first post separately from array returned by wpdb->get_results()
  47. Working with query_posts ( arrays and query strings)
  48. how can i show only the parents in owl-carousel?
  49. Create shortcodes within foreach loop (using array)
  50. Get Current User Id Inside a Loop Returns 0 For a Shortcode
  51. Using a variable in is_page(array())
  52. Random order of WP_Query results with highest meta value
  53. Remove duplicates – array_unique()
  54. How can I add multiple ‘tax_query’ arrays via a loop?
  55. How to properly loop through these external URLs to get them into the sitemap using this hook
  56. The text box have space character
  57. how to remove metadata from the posts of my blog?
  58. How can I create a list of page titles from custom meta values?
  59. Trying to remove post thumbnail with plugin
  60. Recent posts with featured image or fallback image with permalink
  61. Randomly Assign an Image’s Alt Text Based on Data From Post
  62. Call global variable array() in woocommerce child/template
  63. Storing Array from returned database query and using the array in a new query
  64. Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
  65. get_*_meta doesn’t always return an array
  66. get_the_tags() not iterating through for/while loop, but will with foreach
  67. get a simple array of all of the term names that exist in all taxonomies
  68. Populate dropdown with Child Pages based on Parent Page chosen
  69. How to use $query->set with post__in?
  70. Sort custom meta column by other meta value
  71. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  72. Reprinting tags with all attributes
  73. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  74. Creating user status mode in WordPress
  75. Need help with Google drive API [closed]
  76. PHP Array Returning [object Object]. Tried existing answers results with no luck
  77. foreach loop still echoes array
  78. Exclude posts based on meta value
  79. Archive post by meta value + 24hours
  80. Checking array against author id in loop
  81. WordPress update_post_meta updating with empty meta_value field [closed]
  82. Alter required message using comment form api
  83. Advanced Custom Fields – display label and value only if value entered
  84. Is it possible to retrieve all posts with a certain value for metadata?
  85. Get post id within comments loop
  86. meaning of (array)function()
  87. Grouping posts by a custom meta value
  88. Non-Closing PHP Query in WordPress Loop
  89. wp_force_remove_style’ not found
  90. How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
  91. How can I access string value in an array?
  92. How to use if statement in an array? [closed]
  93. How to array only one key from another array
  94. Filtering a function’ output for a new continued function
  95. Output meta into arrays
  96. Querying Database with wpdb
  97. Get html data with javascript to php array and store to wordpress database
  98. How do I create a numbered list with PHP? [closed]
  99. Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?
  100. update_post_meta only updating on last loop of foreach
Categories PHP Tags array, php, post-meta
WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
How can I wrap all blog posts image with

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