Wordpress高级自定义字段get_content

时间:2016-12-15 12:48:56

标签: php wordpress advanced-custom-fields

我有一个功能可以自动在我的标题周围添加一个范围,以便我可以设置范围,例如:

<h2><span>my heading</span></h2>

这在我的常规Wordpress内容中运行良好,但高级自定义字段中的内容将其删除。有没有人有任何想法 - 花了几个小时谷歌搜索。

//add span into each title so can add flourish under span
add_filter('the_content', 'replace_content',1);
function replace_content($content) {
   $content = preg_replace( '/<h(\d{1,6})(.*?)>(.*?)<\/h(\d{1,6}).*?>/', '<h$1><span>$3</span></h$4>',  $content );
   return $content;
}

非常感谢任何可以提供帮助的人!!

1 个答案:

答案 0 :(得分:1)

我还没有尝试过,但ACF有acf/load_value过滤器,可能就是你要找的东西。此挂钩允许您在从数据库加载字段后立即修改字段的值。

documentation的代码示例:

function my_acf_load_value( $value, $post_id, $field )
{
    // run the_content filter on all textarea values
    $value = apply_filters('the_content',$value); 

    return $value;
}

// acf/load_value - filter for every value load
add_filter('acf/load_value', 'my_acf_load_value', 10, 3);

// acf/load_value/type={$field_type} - filter for a value load based on it's field type
add_filter('acf/load_value/type=select', 'my_acf_load_value', 10, 3);

// acf/load_value/name={$field_name} - filter for a specific value load based on it's field name
add_filter('acf/load_value/name=my_select', 'my_acf_load_value', 10, 3);

// acf/load_value/key={$field_key} - filter for a specific field based on it's name
add_filter('acf/load_value/key=field_508a263b40457', 'my_acf_load_value', 10, 3);