简体   繁体   English

将ACF数据显示为Wordpress帖子的“发布”上的帖子标题?

[英]Display ACF data as post title on 'publish' of Wordpress post?

Here is my code: 这是我的代码:

function my_post_title_updater( $post_id ) {

$my_post = array();
$my_post['ID'] = $post_id;

$brand = get_field('brand');
$asset = get_field('asset');
$language = get_field('language');

$countryfield = get_field_object('country');
$countryvalue = get_field('country');
$country = $countryfield['choices'][ $countryvalue ];

if ( get_post_type() == 'project' ) {
  $my_post['post_title'] = $brand . ' ' . $asset . ' ' . $country . ' ' . $language ;
}

wp_update_post( $my_post );

}

add_action('acf/save_post', 'my_post_title_updater', 20);

On publishing a Wordpress post this function is supposed to create a title based on a few Advanced Custom Fields. 在发布Wordpress帖子时,此功能应该基于一些高级自定义字段创建标题。 At the moment what it does is gets 'brand', 'asset' and 'language', but not 'country'. 目前,它的作用是获得“品牌”,“资产”和“语言”,而不是“国家”。 However, upon clicking 'update' of the post it will then display the country in the title. 但是,单击帖子的“更新”后,它将在标题中显示国家。

Any help would be much appreciated. 任何帮助将非常感激。

尝试:

$country = $countryfield['choices'] . $countryvalue;

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

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