在ACF关系字段中获取woocomerce SKU结果

时间:2016-03-14 20:08:22

标签: wordpress woocommerce relationship advanced-custom-fields

我正在尝试将woocomerce sku显示在我使用ACF创建的关系框中。

现在艾略特在以下链接中有一个教程: http://www.advancedcustomfields.com/resources/acf-fields-relationship-result/

然而,我对所有这些都是新手,无论我尝试什么,我得到" null"结果

目标是在标题之前获取SKU(或仅限SKU),以便我们可以通过其sku搜索产品。

艾略特的原始代码:

function my_relationship_result( $title, $post, $field, $post_id ) {

// load a custom field from this $object and show it in the $result
$page_views = get_field('page_views', $post->ID);


// append to title
$title .= ' [' . $page_views .  ']';


// return
return $result;

}



// filter for every field
add_filter('acf/fields/relationship/result', 'my_relationship_result', 10, 4);

我正在尝试使用的那个:

function my_relationship_result( $title, $post, $field, $post_id ) {

// load a custom field from this $object and show it in the $result
$sku = get_field('sku', $post->ID);


// append to title
$title .= ' [' . $sku .  ']';


// return
return $result;

}



// filter for every field
add_filter('acf/fields/relationship/result', 'my_relationship_result', 10, 4);

任何人都可以帮助我吗?



更新
Elliot指着我,也许我需要使用关系字段查询过滤器来修改搜索期间的args:
http://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

WC最有可能将SKU保存在邮递员表(自定义字段数据)中,因此我们可以使用自定义字段meta_query args进行搜索。

任何?

2 个答案:

答案 0 :(得分:0)

__unicode__

答案 1 :(得分:0)

问题是$result变量不存在,只需将return $result更改为return $title

相关问题