Support

Account

Home Forums General Issues get_field not loading values

Solved

get_field not loading values

  • Hello,

    when I execute this code

    
    $dossier = get_field('kgk_dossier_2', 'option');
    
    var_dump2($dossier);
    

    I get int(618) as result. ‘kgk_dossier_2’ is a post_tag taxonomy field and 618 is the id of a post_tag, that doesn’t exist in my database.

    When I save the field on my Options Page with a Value, the page reloads and the field is empty. Some tags work well, other tags behave like this.

    I made a test with my post tag “Ägypten”. It has the id 29.

    I selected it:

    then I saved it and got this:

    get_field returns 618. But when I look it up in my database, there is 29 saved:

    Here is the custom-field php code, that generates the field:

    
    if( function_exists('acf_add_local_field_group') ):
    
    acf_add_local_field_group(array (
    	'key' => 'group_5734337fc8abf',
    	'title' => 'Dossiers',
    	'fields' => array (
    		array (
    			'key' => 'field_57347e182253e',
    			'label' => 'Dossier 1',
    			'name' => 'kgk_dossier_1',
    			'type' => 'taxonomy',
    			'instructions' => 'Tag, der für das erste Dossier genutzt wird.',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'taxonomy' => 'post_tag',
    			'field_type' => 'select',
    			'allow_null' => 1,
    			'add_term' => 1,
    			'save_terms' => 0,
    			'load_terms' => 0,
    			'return_format' => 'id',
    			'multiple' => 0,
    		),
    		array (
    			'key' => 'field_57347e472253f',
    			'label' => 'Dossier 1 Untertitel',
    			'name' => 'kgk_dossier_1_untertitel',
    			'type' => 'textarea',
    			'instructions' => 'Untertitel, der zu dem Dossier angezeigt wird.',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'default_value' => '',
    			'placeholder' => '',
    			'maxlength' => '',
    			'rows' => '',
    			'new_lines' => 'wpautop',
    			'readonly' => 0,
    			'disabled' => 0,
    		),
    		array (
    			'key' => 'field_57347e7822540',
    			'label' => 'Dossier 2',
    			'name' => 'kgk_dossier_2',
    			'type' => 'taxonomy',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'taxonomy' => 'post_tag',
    			'field_type' => 'select',
    			'allow_null' => 1,
    			'add_term' => 1,
    			'save_terms' => 0,
    			'load_terms' => 0,
    			'return_format' => 'id',
    			'multiple' => 0,
    		),
    		array (
    			'key' => 'field_57347e8022541',
    			'label' => 'Dossier 2 Untertitel',
    			'name' => 'kgk_dossier_2_untertitel',
    			'type' => 'textarea',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'default_value' => '',
    			'placeholder' => '',
    			'maxlength' => '',
    			'rows' => '',
    			'new_lines' => 'wpautop',
    			'readonly' => 0,
    			'disabled' => 0,
    		),
    	),
    	'location' => array (
    		array (
    			array (
    				'param' => 'options_page',
    				'operator' => '==',
    				'value' => 'acf-options-dossiers',
    			),
    		),
    	),
    	'menu_order' => 0,
    	'position' => 'normal',
    	'style' => 'default',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => '',
    	'active' => 1,
    	'description' => '',
    ));
    
    endif;
    

    Thank you!
    Max

  • I made a litte bug search. And I tried to query the variable manually.

    
    get_field('kgk_dossier_2', 'option')
    Output: 618
    ----
    get_option('options_kgk_dossier_2', null);
    Output: "29"
    

    I dont get it… :/

  • ah, before this line in acf’s ‘api-value.php’ in function ‘acf_get_value’ its 29:

    
    $value = apply_filters( "acf/load_value/type={$field['type']}", $value, $post_id, $field );
    

    after that its 618. So I have to check the theme and the plugins I guess. Or is that a known bug?

  • Sorry for the comment spam.

    The filter doesn’t come from a plugin or a theme, it’s a filter from the class acf_field in field.php.

    this line in __construct changes my String “29” into a int 618.

    $this->add_filter("acf/load_value/type={$this->name}", array($this, 'load_value'), 10, 3);

    Its the filter acf/load_value/type=taxonomy

    why?

  • I followed the code a litte bit more.

    in ‘api-helpers.php’ in function ‘acf_get_valid_terms’ my value is int(29) before this code:

    
    	// attempt to find new terms
    	foreach( $terms as $i => $term_id ) {
    		
    		$new_term_id = wp_get_split_term($term_id, $taxonomy);
    		
    		if( $new_term_id ) {
    			
    			$terms[ $i ] = $new_term_id;
    			
    		}
    		
    	}
    

    and int(618) after it. but i still don’t know why..

    [edit]
    Output of wp_get_split_term(29, 'post_tag') is 618. So i guess my term database table is broken?

  • “Ägypten” (id: 29) was once a category. I used a plugin to convert the category into a post_tag. My theory is, that wp_get_split_term somehow returns the id of the old category, that doesn’t exist anymore.

  • But I still don’t know, what to do now :/

  • I removed the _split_terms row in my options table. That solved the problem. I know that there are no Plugins, that use old term ids, so that is not a problem I hope.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘get_field not loading values’ is closed to new replies.