Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在自定义文章类型的所有文章中向自定义字段添加文本_Php_Wordpress_Custom Post Type_Custom Fields - Fatal编程技术网

Php 在自定义文章类型的所有文章中向自定义字段添加文本

Php 在自定义文章类型的所有文章中向自定义字段添加文本,php,wordpress,custom-post-type,custom-fields,Php,Wordpress,Custom Post Type,Custom Fields,我试图在自定义字段“results\uhtml”的开头添加一段文本,该字段仅在我的自定义帖子类型“results”上。我想在发布任何结果发布类型时添加此文本。我无法让测试文本显示在字段中。这是我目前掌握的代码 function gr_add_class_div_to_results(){ $field_value = get_field('results_html');; if ($field_value){ $field_value='test'.$field_

我试图在自定义字段“results\uhtml”的开头添加一段文本,该字段仅在我的自定义帖子类型“results”上。我想在发布任何结果发布类型时添加此文本。我无法让测试文本显示在字段中。这是我目前掌握的代码

function gr_add_class_div_to_results(){
    $field_value = get_field('results_html');;
    if ($field_value){
        $field_value='test'.$field_value;
        update_field('results_html', $field_value);
    }
    else{

    }
}


add_action( 'publish_post', 'gr_add_class_div_to_results', 10, 2 );

感谢您的帮助,谢谢

您好,乍一看似乎是if语句的输入错误,您有:if(!field_value){我相信您想要if($field_value){,检查$before字段_value.Hi,谢谢你-我昨晚打得很匆忙。今天早上我试了一下,有没有if语句,代码仍然不起作用,所以我不确定哪里出了问题。