Support

Account

Forum Replies Created

  • Sorry, let me start afresh as I mix the values above. The problem is the same though.

    I found these values in my database;

    meta_key fs_ski_resort_data_fs_email
    meta_value testabc
    meta_key _fs_ski_resort_data_fs_email
    meta_value field_647db09699751

    meta_key fs_ski_resort_data_osm_email
    meta_value test123
    meta_key _fs_ski_resort_data_osm_email
    meta_value field_64b3a3ad40bbf

    I have found that if I do (fs_ski_resort_data is a group name of id group_647d9f906d00a);

    $value1 = get_field(“fs_ski_resort_data_fs_email”, 2022 );
    $value2 = get_field(“fs_ski_resort_data_osm_email”, 2022 );

    I correctly get the result;

    $value1 = testabc
    $value2 = test123

    however, if I do;

    $value1 = get_field(“field_647db09699751”, 2022 );
    $value2 = get_field(“field_64b3a3ad40bbf”, 2022 );

    the result is;

    $value1 = [no value returned]
    $value2 = [no value returned]

    According to the documentation, it says;

    $selector (string) (Required) The field name or field key.

    So as far as I can see, a call like get_field(“field_647db09699751”, 2022 ); should work.

    Why doesn’t this work please?

  • I got it workin outside of a loop, finally, with this;

    update_field('field_64b38c4e3ec56', array(field_64c782fc4c55d=>7), 1123);

    so it is:

    update_field($group_field_name, array($sub_field_name=>$new_value), $post_id)

    I found it from this thread. Search for this sentence, “The true way for update / create a sub field of a group is with this ” by Sebastien Patelski dated October 28, 2021.

    I think this deserves some highlighting in the man pages.

    Again, that you for all your help John Hueber.

  • Thank you very much for the detailed explanation and it makes a lot of sense now.

    When is a subfield not part of a group though?

    I see in the forumn there is one for bugs. Do I add a bug there?

    Thanks again!

  • Yes, that works. Thank you. However, I cannot understand why this doesn’t work:

    $result = update_sub_field(array('field_64b38c4e3ec56', 'field_64c782fc4c55d'), 3, 1110);

  • Hello All. Thanks for the support thus far. If anyone has ideas above above, really appreciated. It now 2 weeks and unable to move forward 🙁 Thank you.

  • You stated, “It is not that confusing, if it is a sub field then you are using the wrong function/method to update the value.” but it is. See below:

    Name: FRESH SNOW SKI RESORTS”
    Key: group_647d9f906d00a

    In the above group I have FIELDS:

    Name: FS SKI RESORT DATA (and it is defined as a group
    Key: field_64b38c4e3ec56

    In above, I have many sub fields and here is an example of one:

    Field Name: qgis_aa_zoom
    Key: field_64c782fc4c55d
    Numeric

    I assume field_64c782fc4c55d (qgis_aa_zoom) is a sub field, right?

    Why does this work (although it does not show in the view as mentioned previously):

    $result = update_field(field_64c782fc4c55d,11, 1110);
    $arraydata = get_field_object(field_64c782fc4c55d,1110);
    echo $arraydata['value'];

    and this not work;

    $result = update_sub_field(array('field_64b38c4e3ec56', 'field_64c782fc4c55d'), 3, 1110);
    $arraydata = get_field_object(field_64c782fc4c55d,1110);
    echo $arraydata['value'];

    Is there any other way to post my php with out giving it to logged in users?

  • Error: Duplicate reply detected; it looks as though you’ve already said that.
    It is so very bizarre and do not understand what is going on. I am hoping you can answer some of my previous questions. It would help me understand what’s going on.

    As already explained under FIELD GROUPS I have:

    Name: FRESH SNOW SKI RESORTS”
    Key: group_647d9f906d00a

    In the above group I have FIELDS:

    Name: FS SKI RESORT DATA (and it is defined as a group
    Key: field_64b38c4e3ec56

    In above, I have many sub fields and here is an example of one:

    Field Name: qgis_aa_zoom
    Key: field_64c782fc4c55d
    Numeric

    Now, if I do this;

                $result = update_field(field_64c782fc4c55d,11, 1110);
                $arraydata = get_field_object(field_64c782fc4c55d,1110);
                echo $arraydata['value'];

    I get 11. If I change to 7, I get 7. It seems to update. Is this because I am creating a new entry as a parent? Why would this work? When I look at my sub field view, it is not updated.

    Now, if I do this:

                $result = update_sub_field(array('field_64b38c4e3ec56', 'field_64c782fc4c55d'), 3, 1110);
                $arraydata = get_field_object(field_64c782fc4c55d,1110);
                echo $arraydata['value'];

    It is not updated and gives me the old value from above on the screen.

  • I find this board buggy too. I have submitted more info and it gives an error saying I said this before, however, it isn’t displayed in the thread.

  • I found the export. I don’t wish to share with everyone the php. Can I send it privately somehow please?.

  • This reply has been marked as private.
  • Did not know I could export php code. I am looking into where that is now.

  • No, I have stated previously that field_64c782fc4c55d is in the group field_64b38c4e3ec56. For field_64c782fc4c55d it says at the top of the group, “sub fields” and field_64c782fc4c55d is under that.

    When I stated acf-field_64b38c4e3ec56-field_64c782fc4c55d, it is from the view html. Here it is again.

    <input type="number" id="acf-field_64b38c4e3ec56-field_64c782fc4c55d" name="acf[field_64b38c4e3ec56][field_64c782fc4c55d]" step="any">

  • Above also explains why I get this error:

    update_sub_field(array(‘field_64b38c4e3ec56’, ‘field_64c782fc4c55d’),11, 1074);
    not a sub_field <– add that to update_sub_field() function.

  • How is it that field_64c782fc4c55d is a sub field and this doesn’t work:

    echo get_sub_field(field_64c782fc4c55d, 1074);

    but this works

    echo get_field(field_64c782fc4c55d, 1074);

  • Hi ACF, I am struggling to understand how to get this working. If someone can please help, much appreciated. Thank you.

  • I have also tried:

    update_sub_field(array('field_64b38c4e3ec56', 1, 'field_64c782fc4c55d'),11, 1074);

    Cannot figure it out.

  • I have traced it down to function acf_maybe_get_sub_field(). This is part of the function:

    	if ( ! is_array( $selectors ) || count( $selectors ) < 3 ) {
    		return false;
    	}

    The number of $selectors is 2 so it fails. Should there be a three?

    If I print_r($selectors) I get:

    Array ( [0] => field_64b38c4e3ec56 [1] => field_64c782fc4c55d )

    …meaning there are only 2 selectors and I guess it is expecting a min of 3, right?

  • Sorry, I see that if I use update_sub_field() outside of have_rows(), I must specify the row and parent. You said this:

    update_sub_field(array('field_64b38c4e3ec56', 'field_64c782fc4c55d'), $value, $post_id);

    I have tried:

    $result = update_sub_field(array('field_64b38c4e3ec56', 'field_64c782fc4c55d'),5, 1074);
    echo $result;

    I get:

    not a sub_field
    0

    I can see where I specify the parent, however, when do I speficy the row. I guess row would be used for a repeater field and assume 1 if not?

    Thanks.

  • Any screen shots of what you are trying to accomplish? It is a bit difficult for me to understand what you are trying to do but maybe that is just me (not an acf expert).

  • I am not an ACF expert at all. I am just learning it, too. There is some great support, in my experience, here but I suggest you try to explain what you have tried thus far.

    One idea is to make open hours and day a repeater field? You could have a dropdown to select the day of the week, and a text box for open time and a text box for close time in 24 hour format, for example. You could also use a time picker to ‘from’ and ‘to’ instead of input boxes. This way you could have several entries for each day (eg. one entry: Monday 0900 1200, next entry: Monday 1300 1700).

    Once you have above working, you would just grab the current time and day.

    $day = date('w', $timestamp); // just one example

    Above would return a number from 0 to 6. 0 is Sunday and 6 is Saturday.

    Then you would loop the repeater field to find that day if it existed.

    Then you would grab the time. Lots of ways to do that.

    Then you would loop the repeater field to see if it falls between from/to.

    If true, it is open and you just need to calculate the current time to the next close time and then maybe the next open time. If false, you would search for the next open day and time and calculate the time.

    Maybe you could add another field to log national holidays or other closed days. It could be a date with a input field for comments. The first loop would test to see if today was a national holiday or a store closer and echo the comment field could mention the reason why the store was closed.

    Just ideas. Hope this helps. Try to get the first step of capturing the day, from-time and to-time in a repeater field.

  • Per far above, I have already tried;

    update_sub_field(field_64c782fc4c55d, 84, 1074);

    and it does not work even if the value changes.

    I found update_sub_field(); in /plugins/advanced-custom-fields-pro/includes/api/api-templated. I added some debugging code to it, too.

    function update_sub_field( $selector, $value, $post_id = false ) {
    
    	// vars
    	$sub_field = false;
    
    	// get sub field
    	if ( is_array( $selector ) ) {
    
    		$post_id   = acf_get_valid_post_id( $post_id );
    		$sub_field = acf_maybe_get_sub_field( $selector, $post_id, false );
    	
    	} else {
    		echo 'The $selector is '.$selector.', the $value is '.$value.' and the $post_id is '.$post_id;
    		echo ' Also, this is not an array</br>';
    		$post_id   = acf_get_loop( 'active', 'post_id' );
    		echo 'post_id: '.$post_id.'</br>';
    		$sub_field = get_row_sub_field( $selector );
    		echo 'sub_field: '.$sub_field.'</br>';
    		echo $post_id;
    	}
    
    	// bail early if no sub field
    	if ( ! $sub_field ) {
    		echo "not a sub_field</br>";
    		return false;
    	}
    
    	// update
    	echo "hello".$value.'//'.$post_id.'//'.$sub_field.'</br>';
    	
    	return acf_update_value( $value, $post_id, $sub_field );
    
    }

    The output of the above is;

    The $selector is field_64c782fc4c55d, the $value is 84 and the $post_id is 1074 Also, this is not an array
    post_is:
    sub_field:
    not a sub_field

    post_id is not returned, sub_field is not return and it bails early as it is not a sub_field.

  • Even this board is buggy! Wrote an entirely different reply to above and my oly reply is posted. Rewriting now.

  • Per far above, I have actually tried:

    
    update_sub_field(field_64c782fc4c55d, 84, 1074);

    And it does not update even if the value is different from the current value.

    According to the man page, $selector can be a string, too,

    $selector (string|array) (Required) The sub field name or key, or an array of ancestors and row numbers.
    $value (mixed) (Required) The new value.
    $post_id (mixed) (Optional) The post ID where the value is saved. Defaults to the current post.

Viewing 25 posts - 1 through 25 (of 40 total)