Support

Account

Home Forums Bug Reports Slugbug?

Unread

Slugbug?

  • I’ve been using the options addon and I have found what I think might be a bug, perhaps even two.

    First when creating a new options page with a custom slug like this:

    
    if( function_exists( 'acf_add_options_sub_page' ) ) {
    	acf_add_options_sub_page( array(
    		'title' => 'My title',
    		'slug' => 'my-custom-slug'
    	));
    }
    

    This works fine, but when I then start to add fields, the fields won’t show up. I have more than double checked the location parameters and also had other people look at it. When I don’t use a custom slug, it works alright. So that seems to be a bug.

    The second bug is when I try to get values from the options page using get_field(); It returns false, but I am positive the value of that field is in the DB. I tried to debug it and got stuck at line 332 in api.php. The filter acf/load field is returning ‘false’ there. But I have no clue as to why.

    I hope this is a clear enough explanation of what I tried and what seems to be going wrong.

    Regards,

    Mark

  • Hi @YourMark
    Thanks for the bug report.

    Just to clarify, using the code above you are not able to select the sub options page as a field group location rule?

    As for the get_field issue, can you post the full code you are using to get the value?

    Thanks
    E

  • Hey Elliot,

    I can select the suboptions page in the interface, but fields are just not shown. Also not if I do this via code.

    For the field issue, I use this code to create a field:

    
    array (
    	'key' => 'field_5266967c15e4a',
    	'label' => 'Field',
    	'name' => 'field-name',
    	'type' => 'text',
    	'default_value' => '',
    	'placeholder' => '',
    	'prepend' => '',
    	'append' => '',
    	'formatting' => 'html',
    	'maxlength' => '',
    ),
    

    And I use this code to get the field value

    
    get_field( 'field-name', 'options' );
    

    But when I dump the result, I get a false.

  • Hi @YourMark

    You ay that you are getting ‘false’ as a result from get_field. Isn’t this because you haven’t saved any data due to your first issue?

    I think we should ignore this get_field issue for now in light of this.

    As for the slug issue. I have tracked down and found the source of the issue.
    The problem is a piece of code which provides compatibility from older versions of ACF data.

    I think this can now be removed as it is obviously causing a major issue. I’ll remove the code and push the fix to github.

    Can you download the latest code from github and test?

    Thanks
    E

  • Hello Elliot,

    thanks for your reply.

    I worked around the first issue by not picking a custom slug but using the normal one that is generated from the options page name. Then I can create custom fields on the options page.

    When I do that and save those fields, they do show up in the database, but get_field() returns false.

    Thank you for the update, I will try it out and get back on it and let you know if it works.

  • I have tried the updated version from GIT. It works fine, thank you.

    However, the get_field() bug, still remainds. A value stored from an options page, can not be retrieved by using the_field or get_field. Those functions still return false.

  • Hi @YourMark

    Can you change your field name to use an underscore instead of dash?
    Also, can you rename it from ‘field-name’ to something ore useful?

    Also, where are you using this code? Is it in the root of your functions.php file?

  • That is just the code I used here to describe the problem. My actual code looks like this:

    
    if(function_exists("register_field_group")) {
    	register_field_group(array (
    		'id' => 'acf_webinar',
    		'title' => 'Webinar',
    		'fields' => array (
    			array (
    				'key' => 'field_525fffb950527',
    				'label' => 'Webinar code',
    				'name' => 'webinar_code',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'course',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    				array (
    					'param' => 'page_type',
    					'operator' => '==',
    					'value' => 'child',
    					'order_no' => 1,
    					'group_no' => 0,
    				),
    				array (
    					'param' => 'page_parent',
    					'operator' => '==',
    					'value' => $this->options['webinar_parent'],
    					'order_no' => 2,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'side',
    			'layout' => 'default',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    }

    Now, when I use either get_field( ‘webinar_code’ ) or the_field( ‘webinar_code’ ), it returns false even though a value is stored.

    The get_field() function doesn’t work anywhere, I tried it in several files.

  • Hi @YourMark

    Your field group contains 3 location rules which will never return true for ALL of them being correct on the same page.

    All 3 rules are in the same ‘AND’ group. You need to break out the options rule into it’s own group to make it an ‘OR’.

    You can use the ACF UI to create the field group, then export the field group to PHP and see how the location rules are grouped in arrays.

    As for the get_field function. Please describe where you have used it. and Provide the code too.

    Thanks
    E

  • Hello Elliot,

    sure enough those conditions can all be true.

    If the post is of post type course AND it's a child AND it's a child of the post with a value stored in $this->options['webinar_parent']. Come to think of it, I can remove the second statement, but it still works.

    The fields all do show up on the right places, that all works nicely. I do always make the fields in the UI and then export it to PHP. Works like a charm.

    The value from the field is also stored in the DB. No problems there.

    The example above about the webinar code was a poor one, since that one does not show up on an options page.

    
    if(function_exists("register_field_group")) {
    	register_field_group(array (
    		'id' => 'acf_webinar-settings',
    		'title' => __( 'Webinar settings', 'ictrecht' ),
    		'fields' => array (
    			array (
    				'key' => 'field_5266959515e47',
    				'label' => __( 'Parent', 'ictrecht' ),
    				'name' => 'webinar_parent',
    				'type' => 'select',
    				'choices' => array (
    				),
    				'default_value' => '',
    				'allow_null' => 1,
    				'multiple' => 0,
    			),
    			array (
    				'key' => 'field_5266967c15e4a',
    				'label' => __( 'Price', 'ictrecht' ),
    				'name' => 'webinar_price',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '€',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5266973215e4b',
    				'label' => __( 'Price for lawyers', 'ictrecht' ),
    				'name' => 'webinar_lawyer_price',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '€',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => '',
    			),
    			array (
    				'key' => 'field_5266975c15e4c',
    				'label' => __( 'Registration form', 'ictrecht' ),
    				'name' => 'webinar_registration_form',
    				'type' => 'select',
    				'choices' => array (
    				),
    				'default_value' => '',
    				'allow_null' => 1,
    				'multiple' => 0,
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'options_page',
    					'operator' => '==',
    					'value' => 'courses_settings',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'normal',
    			'layout' => 'default',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    }

    This is a good example.

    If I now on a single page want to use webinar_price, I try to do this:

    echo get_field( 'webinar_price', 'option' );
    Or
    echo get_field( 'webinar_price', 'options' ); // Should do the same, but tried this one too

    But it doesn’t work. If I var dump the return value from get_field I get a false in both cases.

  • Hi @YourMark

    Can you confirm that a value is definitely saved in the DB?
    Can you edit the options page and modify the value and it is saved?

    Thanks
    E

  • Perhaps there is an issue with 4.3 and loading values from a registered field group…

    I’ll do some testing and let you know. This may not be specific to the options page, but to registering any field.

    Thanks
    E

  • Hi @YourMark

    I have tried but can’t reproduce the issue. Are you able to provide me with login details to have a look at this myself?

    Thanks
    E

  • Hello Elliot,

    My apologies for my late response.

    I found some more issues with ACF extensions. For instance the repeater date/time picker. If I use a custom date_format and time_format sometimes the values that are filled in are not being stored in the DB. It counts the field, the number of fields that are filled in is upped in the DB, just not the value that was chosen.

    Somehow I am experiencing a lot of issues, I think I might need to try all this on a clean WP install and see what happens. I will do so asap and see what happens.

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

The topic ‘Slugbug?’ is closed to new replies.