S
S
Sergey Burduzha2018-06-21 09:20:07
WordPress
Sergey Burduzha, 2018-06-21 09:20:07

Why doesn't the "carbon_fields_register_fields" hook work?

Installed the Carbon Fields plugin.
I registered insurance in the functions.php file

if ( ! function_exists( 'carbon_get_post_meta' ) ) {
    function carbon_get_post_meta( $id, $name, $type = null ) {
        return false;
    }   
}

Here I brought one function, in fact, I registered everything from the documentation.
Next, I wrote a hook for connecting arbitrary fields from files
add_action( 'carbon_fields_register_fields', 'crb_attach_post_options' );
function crb_attach_post_options() {
    // путь к пользовательскому файлу определения поля (полей), измените под себя
    require_once __DIR__ . '/inc/carbon-fields/home-fields.php';
}

And here is the code from the home-fields.php file, nothing special
use Carbon_Fields\Container;
use Carbon_Fields\Field;

Container::make( 'post_meta', 'Текст слайдера' )
     ->show_on_post_type('page') // этот метод можно не писать, так как show_on_post_type('post') по умолчанию
     ->show_on_page('glavnaya')
         ->add_fields(array(
             Field::make('text', 'home_slider_text_1', 'Текст слайдера')
             ->set_width(33),
             Field::make('text', 'home_slider_text_2', 'Текст слайдера')
             ->set_width(33),
             Field::make('text', 'home_slider_text_3', 'Текст слайдера')
             ->set_width(33)
         ));

So here's the problem:
If I just prescribe
require_once __DIR__ . '/inc/carbon-fields/home-fields.php';

in functions.php, then custom fields appear on the page.
If I write the path to the file in the body of the hook function, there are no fields.
It doesn't work like this.
5b2b439384c05876584230.jpeg
Why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
campusboy, 2018-06-21
@serii81

Hello. Classic mistake. You appear to be using the carbon_fields_register_fields hook , but are running CF 1.6. This hook appeared in CF v 2.0. Version 1.6 had the carbon_register_fields hook .
From my own advice, download CF 2.2 as a plugin and install it, since you are just getting started. There is nothing to loose. Version 1.6 is no longer developed, it does not have much that is in 2.2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question