i'm trying to query posts from the post type Product that match with the current post in the loop from the post type Item, based on the custom fields product-ean and item-ean.
For example: i have a Item post with item-ean 123 and 2 Product posts with product-ean 123. Now i would like to show both Product posts on the Item post.
Help is greatly appreciated, thank you.
Menno
i'm trying to query posts from the post type Product that match with the current post in the loop from the post type Item, based on the custom fields product-ean and item-ean.
For example: i have a Item post with item-ean 123 and 2 Product posts with product-ean 123. Now i would like to show both Product posts on the Item post.
Help is greatly appreciated, thank you.
Menno
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 );