请任何人指导我如何在函数中添加ACF字段。我所做的一切一事无成。
add_action('woocommerce_after_main_content', 'custom_seo_block', 10);
function custom_seo_block() {
return "<?php the_field('seo_content'); ?>";
}
预先感谢
答案 0 :(得分:0)
add_action('woocommerce_after_main_content', 'custom_seo_block', 10);
function custom_seo_block() {
$value = get_field( "seo_content", $post_id );
return $value;
}
通过帖子ID获取ACF字段值,然后将其返回。
答案 1 :(得分:0)
它仍然没有返回数据。抱歉,这是一个愚蠢的问题。显然这里做错了。
add_action('woocommerce_after_main_content', 'custom_seo_block', 10);
function custom_seo_block() {
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5c52deb4b5fe0',
'title' => 'SEO content',
'fields' => array(
array(
'key' => 'field_5c52dec5d99a4',
'label' => 'SEO content',
'name' => 'seo_content',
'type' => 'wysiwyg',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'tabs' => 'all',
'toolbar' => 'full',
'media_upload' => 1,
'delay' => 0,
),
),
'location' => array(
array(
array(
'param' => 'taxonomy',
'operator' => '==',
'value' => 'all',
),
),
),
'menu_order' => 5,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
}
答案 2 :(得分:0)
add_action('woocommerce_after_main_content', 'custom_seo_block', 10);
function custom_seo_block() {
global $post;
the_field('seo_content',$post->ID);
}