使用 acf 关系字段从自定义 post 类型中获取与特定分类相关的所有 post

Get all posts from a custom post type that are related to specific taxonomy with acf relationship field

我有一个名为 'Adverts' 的自定义 post 类型,其中我有一个高级自定义字段调用每个 post 的图像。然后我有一个名为 Listings 的自定义 post 类型,其中包含一个名为 'Area' 的分类法,每个地区都有不同的术语。

如何从仅与一个特定术语(区域)关联的广告中调用所有 post?

我用这个查询解决了它 - 'channel' 是我的分类术语,listing_area 是我的分类。 'associate_adverts' 是关系字段,'adverts' 是我从中提取它们的 post 类型。

<?php if (has_term( 'channel', 'listing_area' )) { ?>


<?php
        $posts = get_posts(array(
'numberposts'   => 3,
'post_type'     => 'adverts',
'order_by' => 'title',
'order' => 'random',
'meta_query'    => array(
    'relation'      => 'AND',
    array(
        'key'       => 'associate_adverts',
        'value'     => '1822',
        'compare'   => 'LIKE',
    )
),
));

    ?>

  <?php //if it's returning the object

    foreach($posts as $advert){

        echo $advert->post_title; //member name

                 }?>

       <?php }
        ?>