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

Use WP_query to match post types based on custom field values

In the WP Docs you can find the answer.

I have not tested this snippet, but it should become something like this:

$args = array(
    'post_type'  => 'product',
    'meta_query' => array(
        'relation' => 'AND',
        array(
                'key' => 'product-ean',
                'value' => 123,
                'compare' => '=',
        ),
        array(
                'key' => 'item-ean',
                'value' => 123,
                'compare' => '=',
        ),
    ),
);
$query = new WP_Query( $args );

Related Posts:

  1. Using Query Posts With Multiple Post Types And A Taxonomy
  2. Can’t sort order of wp_query with 2 meta keys
  3. Display custom post type from dynamic custom field
  4. Get posts between custom dates
  5. find custom post type post by searching its custom field with my string
  6. WP_Query of custom post type sorted by meta_key has unexpected results
  7. WP_Meta_Query object with conditionals
  8. WordPress custom post type
  9. Custom Query With Multiple Meta Key Value
  10. Querying meta values within an array
  11. Two near-identical custom field types – one works, the other doesn’t . What can cause this?
  12. Archive for custom taxonomy lists all posts instead of current taxonomy
  13. wp_query check if integer exists in custom field’s array
  14. Get latest 3 posts from multiple CPT in one query
  15. Fetch Record based on meta key dates
  16. A method for ordering mixed dates in search result loop (theory only, no actual code)
  17. How to do WP_Query with two meta fields with orderby clause
  18. Stuck in Order by more then one
  19. how to make members list directory through wordpress post custom meta key.
  20. Why is this query not working? (Standard posts + custom post type)
  21. Polylang non-default language ignores tags in WP_Query
  22. WordPress request fiter order by related post’s post_title
  23. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  24. Configuring a meta query with multiple post types that have the same relationship on a single page
  25. Different Ways to Query Custom Post Types?
  26. Possible to filter custom post type with multiple meta data?
  27. pagination not working for category.php (custom post types in categories)
  28. Query based on custom fields start and end date
  29. How to display Related Posts based on number of taxonomy terms matched
  30. Filter date from post meta when date is in string format
  31. How to make WP_Query not to show irrelevant posts?
  32. Loop for custom post types filtered by a taxonomy
  33. Displaying a div from an assigned meta_value when on a page
  34. WP_query – Filter by tax_query and meta_query using multiple select
  35. How to get specific post meta by title or id
  36. Custom post type, custom taxonomy, query posts only from taxonomy (children of)
  37. Getting a custom post’s custom field based on another custom post’s custom field select
  38. Querying multiple values from a single key
  39. Pagination not working on custom query on a page
  40. FacetWP paging custom wp_query
  41. $post->post_meta not pulling any post in wordpress/php
  42. Returning a custom content types with meta values
  43. Can’t change posts per page in WordPress Post Type Query
  44. postsperpage value not being applied
  45. Create a WP_Query where if the first value of the first row is equal to the second compare other value
  46. Query Posts, order by meta value
  47. Sorting by meta_key different to search criteria?
  48. Using WP meta query to show custom post types by a start and finish date
  49. Two queries – one with checkbox ticked, one without – comparing meta_query
  50. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  51. HM CMB: Post Select Field for CPT ID
  52. Custom Post Type Query W/Category Dropdown
  53. Find Posts based on Child Post value
  54. Custom Post Type ‘Event’: Chronological list of recurring events from meta_values in array
  55. Sorting the Loop by Taxonomy Value
  56. Custom Query: Multiple CPTs and a taxonomy filter
  57. WP query_posts group by meta field related
  58. How to order query results based on if a custom field has been populated, then the order by the date of the post?
  59. Custom wp-query display post only today
  60. After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
  61. How do i create a custom post query when the meta value is an array?
  62. custom post type and a “sticky” position taxonomy
  63. build child and anchestor three from post parent
  64. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  65. meta query condition don’t work
  66. Custom query result empty on page 2
  67. How to sort by multiple values in a nested WP_Query
  68. Show posts from WP Custom Post Type selected from a field in a metabox
  69. Custom meta fields not showing up in WP_Response Object via custom endpoint
  70. meta query multiple values for the same key
  71. How to get post by meta value
  72. Sort custom post archives by a meta value from a different custom post type?
  73. Custom post types – meta_query: search lesson which starts sooner
  74. How do I get all authors posts of a custom post type outside loop
  75. minimize wp_query call to database
  76. post type => ‘any’ not applied my custom queries
  77. How to get the posts that my following users are liked?
  78. Meta_Query refuses to return results
  79. Linking posts together with Advanced Custom Fields “both ways”
  80. Query the title of the page to show posts with matching category in the loop
  81. Not able to get my custom search result using meta_query and tax_query together?
  82. update a posts of other custom post type
  83. How to get Current week and current date record wp query
  84. How to get post meta for custom post type and taxonomy
  85. Querying, storing, and using data from 2 separate custom post types
  86. get_post_meta for Custom Post Type ( CPT )
  87. Main site single-property.php design, as homepage of a multisite
  88. Query events post type after current date and timezone
  89. Conditional posts in WP_query for search
  90. Imported Content Doesnt Show Up On Frontend
  91. meta query always fails even if data is correct
  92. display news with pictures 3 small and one large (loop)
  93. Selecting posts older than the current Unix epoch timestamp
  94. Custom Post Type meta oembed html output resulting in WSoD
  95. Filter RSS feed for custom post type to events for next 7 days only
  96. Values inside a custom field to determine which category posts to display
  97. Custom post type blog pagination conflict
  98. Query Posts From Multiple Post Types
  99. Trying to combine multiple WordPress queries
  100. Return only custom post types for the page, not all
Categories custom-post-types Tags custom-post-types, meta-query, post-meta, query-posts, wp-query
WordPress inserting ?q= in URLs
wordpress-theme 2017: featured image behaviour: where to set the height of the featured image?

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