【问题标题】:Including AFC field in functions.php在functions.php中包含AFC字段
【发布时间】:2019-06-25 17:37:51
【问题描述】:

谁能指导我如何在函数中添加 ACF 字段。我所做的一切都没有回报。

add_action('woocommerce_after_main_content', 'custom_seo_block', 10);

function custom_seo_block() {
    return "<?php the_field('seo_content'); ?>";
}

提前致谢

【问题讨论】:

标签: wordpress advanced-custom-fields


【解决方案1】:
add_action('woocommerce_after_main_content', 'custom_seo_block', 10);

function custom_seo_block() {
global $post;
the_field('seo_content',$post->ID);
}

【讨论】:

    【解决方案2】:

    它仍然没有返回数据。对不起,如果这是一个愚蠢的问题。显然这里做错了什么。

    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;
    }
    

    【讨论】:

      【解决方案3】:
      add_action('woocommerce_after_main_content', 'custom_seo_block', 10);
      
          function custom_seo_block() {
          $value = get_field( "seo_content", $post_id );
              return $value;
          }
      

      通过 post id 获取 ACF 字段值,然后返回它。

      【讨论】:

        猜你喜欢
        • 2013-10-24
        • 1970-01-01
        • 1970-01-01
        • 2013-06-29
        • 2019-07-25
        • 2019-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多