简体   繁体   English

获取Wordpress ACF分类,并添加到类别

[英]Get Wordpress ACF Taxomony and add to category

I am using ACF to get the taxonomy, How to I get $place (which is the selected taxonomy) and add it to the installgallery_places post query? 我正在使用ACF来获取分类法,如何获取$ place(已选择的分类法)并将其添加到installgallery_places发布查询中? My code is: 我的代码是:

<?php $place = get_field('choose_place', 'installgallery_places'); $args = array( 'post_type'=> 'installgallery', 'installgallery_places'=> '$place' );
$the_query = new WP_Query( $args ); if($the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

I believe you can do it like that 我相信你可以那样做

 $args = array( 
    'post_type'=> 'installgallery', 
    'meta_query' => array(
                      array(
                        'key' => 'installgallery_places',
                         'value' => $place,
                         )
                    )


  );

Maybe it could work with you original code if you remove the single quotes around the variable $place 如果删除变量$place周围的单引号,也许它可以与您的原始代码一起使用

Worked this one out from trial and error, had to change the ACF taxonomy to 'Term Object' in the Return Value and used the following code to return the slug: 从反复试验中解决了这一问题,不得不将返回值中的ACF分类标准更改为“术语对象”,并使用以下代码返回该段代码:

<?php
$variable = get_field('choose_place');
$args = array(
'post_type'=> 'installgallery',
'installgallery_places' => $variable->slug
);              
$the_query = new WP_Query( $args );

Thanks for your help on this one 感谢您对此的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM