来自循环的自定义分类法的子列表(Wordpress + ACF Pro)

问题描述 投票:0回答:1

我正在使用最新版本的acf pro和wordpress。我有一个灵活的内容字段,我想在其中显示某些事件。显示的事件应通过分类法字段进行选择,在该字段中可以通过复选框选择自定义后分类法(位置)的多个条目(城市)。 (多选)返回是一个分类对象。我需要一个来自选定字段的子弹列表。该列表应为例如:“慕尼黑”,“伦敦”,

相关代码是

<?php 
$locations = get_sub_field('select_locations');
$loop = new WP_Query( array( 'post_type' => 'events', 'posts_per_page' => 99, 


        'tax_query' => array(
            array(
                        'taxonomy' => 'locations',
                        'field' => 'slug',
                        'terms' => array(
                            /* HERE SHOULD BE THE LIST */
                        )
                    )
        ) 
) ); 

?>

我尝试了几件事,但无法正常工作。如果有人可以帮助我,我将非常高兴。

非常感谢。

wordpress advanced-custom-fields custom-taxonomy
1个回答
0
投票

尝试此

$category_slug_arr = array('example-slug-1', 'example-slug-2', 'example-slug-3');

$args = array(
    'posts_per_page'   => -1,
    'orderby'          => 'date',
    'order'            => 'DESC',
    'post_type'        => 'events',
    'post_status'      => 'publish',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'locations',
            'field'    => 'slug',
            'terms'    => $category_slug_arr,
            'operator' => 'IN'
        )
    )
);

$loop = new WP_Query( $args );

echo '<pre>'; print_r($loop->posts); echo "</pre>";
© www.soinside.com 2019 - 2024. All rights reserved.