Включение поля AFC в functions.php - PullRequest
0 голосов
/ 01 февраля 2019

Может кто-нибудь подсказать мне, как добавить поле ACF в функцию, пожалуйста.Все, что я делаю, ничего не возвращает.

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

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

Заранее спасибо

Ответы [ 3 ]

0 голосов
/ 01 февраля 2019

Это все еще не возвращает данные.Извините, если это глупый вопрос.Очевидно, что здесь что-то не так.

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;
}
0 голосов
/ 01 февраля 2019
add_action('woocommerce_after_main_content', 'custom_seo_block', 10);

function custom_seo_block() {
global $post;
the_field('seo_content',$post->ID);
}
0 голосов
/ 01 февраля 2019
add_action('woocommerce_after_main_content', 'custom_seo_block', 10);

    function custom_seo_block() {
    $value = get_field( "seo_content", $post_id );
        return $value;
    }

Получить значение поля ACF по идентификатору записи и затем вернуть его.

...