
Hi guys,
I’m trying to do WP_Query to retrieve data from two different post types “articles” & “webinars” but the problem is that I need to filter these data and show only the data that equal to the title of expert this will be written inside two different repeater fields “article_expert” for the “articles” post type and “webinar_expert” for “webinars” these repeaters is sub to the fields called “article_by” for “articles” and “webinar_by” for “webinars”. Below the code that I’m written hope you can help me to fix this issue:
<div class=”row”>
<?php
$expert_name = get_the_title();
$second_query = new WP_Query( array(
‘post_type’ => array(‘articles’, ‘webinars’),
‘posts_per_page’ => 4,
‘ignore_sticky_posts’ => 1,
‘meta_query’ => array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘article_expert’,
‘value’ => $expert_name,
‘compare’ => ‘===’,
),
array(
‘key’ => ‘webinar_expert’,
‘value’ => $expert_name,
‘compare’ => ‘===’,
),
),
‘orderby’ => ‘rand’,
) );
if($second_query->have_posts()) {
while ($second_query->have_posts() ) : $second_query->the_post();
?>
<div class=”col-lg-3 col-sm-6″>
“>
<div class=”article”>
<div class=”article-img”>
<?php if (get_post_type() === ‘articles’) { ?>
” class=”img-fluid”>
<?php } else{ ?>
” class=”img-fluid”>
<?php } ?>
</div>
<div class=”article-info”>
<h6>Article</h6>
<h6><?php the_title_attribute(); ?></h6>
</div>
</div>
</div>
<?php
endwhile; wp_reset_query();
} ?>
</div>