I have 2 custom post types “Shops” and “Restaurants”.
Each of these have custom fields associcated with them.
For example, One field in Shops is “Shop ID” and one in Restaurants is “Restaurant ID”.
I want to query both Custom Post Types and if Shop ID is 20, I want to display all Restaurants with ID 20.
I’ve been toying with this code:
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'shops', 'restaurants',
'meta_query' => array(
'relation' => 'AND',
array(
'meta_key' => 'shop-id',
'meta_value' => '12345',
'compare' => '='
),
array(
'meta_key' => 'restaurant-id',
'meta_value' => '12345',
'type' => 'NUMERIC',
'compare' => '>'
)
)
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h4>
<a href="https://wordpress.stackexchange.com/questions/203529/<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h4>
<?php endwhile; ?>
<?php endif; ?>
Note I’m also using Advanced Custom Fields.