使用分类字段ACF的选定值填充帖子对象字段 [英] Populate Post Object field with selected value of taxonomy field ACF

查看:20
本文介绍了使用分类字段ACF的选定值填充帖子对象字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个字段:

  1. 名为&Quot;Category&Quot;的类型分类
  2. 键入名为";Products&Quot;的POST对象

我想要什么?仅选择";类别";填充";Products";的下拉列表。

我正在尝试:

function filter_product_query( $args, $categorId ) {    
    
    $categorId = get_field('category_v1');
    
    $args = array(
        'post_type' => 'product',
        'posts_per_page' => 3,
        'tax_query'      => array( array(
            'taxonomy'   => 'product_cat',
            'field'      => 'term_id',
            'terms'      => $categorId ,
        ) )
    );          
    return $args;
    
}
add_filter('acf/fields/post_object/query/key=field_61e745e87a5a6', 'filter_product_query', 10, 4);

但不起作用。

Taxonomy field configuration

Post object field configuration

推荐答案

我也在处理此问题。

现在,首先。如果根本没有调用该函数,则返回。那么,很可能是您使用了错误的钩子。还有一个名为

的钩子

以下是帮助我的人 https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-result/

还有其他人。请密切注意挂钩文本,因为它可能不是POST_OBJECT。

如果要调用您正在使用的函数,则必须按照以下步骤操作,因为我猜这与此问题有关

https://support.advancedcustomfields.com/forums/topic/send-additional-field-for-ajax-update-event-on-selecttaxonomy/

可能还有这个,它引用了上面的内容。 https://support.advancedcustomfields.com/forums/topic/trouble-with-acffieldspost_objectquery-filter/

这篇关于使用分类字段ACF的选定值填充帖子对象字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆