Support

Account

Forum Replies Created

  • background: 2 year old code stable code base that uses get_fields to return all values that have been previously saved to the post via update_field function.

    1. As of yesterday, the get_fields function is returning a NULL for one field.
    2. get_field('name', $post_id) returns the value properly.
    3. Running a var_dump shows the field name in the array with a value of NULL
    4. Validated that both the field_key and field_name has not changed.

    Does anyone have an idea or recommendation of what to look at in the database to determine what has changed? Perhaps there is an issue with the ACF relational data table?

    Thank you for your assistance.

    Jeff

  • John not sure what happened with the posts above, out of order and missing a key sentence.

    Thank you for your help. I noticed the same thing and it was a typo here when I was describing my issue.

  • Widening the look at my code:

        acf.add_action('append', function( $el ){
    
    // The Keys
            layoutKey = 'field_5f498c46f5b9f';       // Layout
            fieldKey = 'field_58dd1b4f4b510';     // Post Object, returns a post id
            
    // Vars
    
            var firstFields = acf.getFields({type: 'post_object', key: fieldKey });
    
            console.log ('Fields Loaded ... New Layout Appended');
    
    // The Count / Index of new entry (Remember the first row is 0)
    
            theCount = firstFields.length;
            newEntry = firstFields.length - 1;
    
    // Do we have an object we can work with?  Set a Status -- Yes this works
    
            firstFields[newEntry].showNotice({
            text: 'This is the field we are trying to set',
            type: 'success',
            dismiss: true
        });
    
    // Retrieve value from Previous Layout 
    
        for (i = 0; i < theCount; i++) {
                // Get the value from the previous record
                if (i == (theCount - 2)) {
    
                    priorValue = firstFields[i].val();    // is the post_id of the selected item
    
                    console.log(priorValue);
                }
    
                if (i == newEntry) {
    
    // Try and set the post id to the field
    
                    firstFields[i].val(priorValue);
                    
    // Trying this ... no change.
                    firstFieldsi].trigger('change');
    
     
    
                }
    
    }
  • Additionally, I changed the field to standard selects and text fields and it works as intended. Even without the trigger(‘change’)

    When I try and use a post_object field the default ‘Select a Value’ remains displayed and the value does not set.

  • Thanks John,

    I noticed that after I entered into the forums and compared to my code and it was a typo here.

    Widening the look at my code:

        acf.add_action('append', function( $el ){
    
    // The Keys
            layoutKey = 'field_5f498c46f5b9f';       // Layout
            fieldKey = 'field_58dd1b4f4b510';     // Post Object, returns a post id
            
    // Vars
    
            var firstFields = acf.getFields({type: 'post_object', key: fieldKey });
    
            console.log ('Fields Loaded ... New Layout Appended');
    
    // The Count / Index of new entry (Remember the first row is 0)
    
            theCount = firstFields.length;
            newEntry = firstFields.length - 1;
    
    // Do we have an object we can work with?  Set a Status -- Yes this works
    
            firstFields[newEntry].showNotice({
            text: 'This is the field we are trying to set',
            type: 'success',
            dismiss: true
        });
    
    // Retrieve value from Previous Layout 
    
        for (i = 0; i < theCount; i++) {
                // Get the value from the previous record
                if (i == (theCount - 2)) {
    
                    priorValue = firstFields[i].val();    // is the post_id of the selected item
    
                    console.log(priorValue);
                }
    
                if (i == newEntry) {
    
    // Try and set the post id to the field
    
                    firstFields[i].val(priorValue);
                    
    // Trying this ... no change.
                    firstFieldsi].trigger('change');
    
     
    
                }
    
    }
  • Moti,

    Try removing the enclosing brackets around the value as follows:

    $args[‘name’] = ‘value’;

  • John I agree and thank you.

    Perhaps not the right section to post in and I did not find anything here yet, but was curious if anyone had worked this out individually and it would solicit a response.

    I am about to tackle this and will post my code here if anyone else is interested.

    Thank you.

    Jeff

  • AVWingz,

    Do a test by adding the ‘field_groups’ => array(‘12345’) option to the acf_form(), where 12345 is the ID of the field group you want to see.

    Does it come back then?

    Jeff

  • Hello Nessler,

    The user field allows you to choose three options to return data.

    1. User Array
    2. User Object
    3. User ID

    With the first being the default. You have a few options here to get the data you want.

    Since this is an array, you can do a little digging and use something like this in your template to find the exact fields you want to display:

    <?php var_dump( get_field('coauteurs') ); ?>

    Then once you pick the fields you want, you can do something like this:

    <?php 
    
    // Get the user
    
    $user_data = get_field('coauteurs');
    
    echo $user_dzata['display_name'];
    
    ?>

    Hope this helps.

    Jeff

  • More info …

    The field exists.
    If you call the function from the post type the field exists in you can update the field.
    I can use get_posts to retrieve data from the second post type I am trying to save to.

  • Thanks John. Looks like the forum is working. Did you remove the post?

  • Found it.

    When you add an SSL certificate to your site you need to add the HTTPS:// in the site settings as well.

    If you don’t you will get a cross domain error when your site attempts to retrieve data via AJAX.

    Good times.

  • This reply has been marked as private.
  • Elliot,

    My apologies for not getting back here quickly. We were able to roll the site back to an earlier version that is working.

    Since our staging site is local, access other than the live site was unavailable.

    Our plan is to create a staging site online and test moving everything forward and finding what caused the site to become inoperative. I will make sure to come back and give you feedback as to what we found. I suspect from other support requests that you may have found it and fixed it by now.

    Thank you again.

    Regards,

    Jeff

  • Certainly.

    I will need to take the site into maintenance mode to give you access so live users are not affected. Can we schedule a time frame?

    Jeff

  • I have now tested other Relational Fields and they will not return data in FireFox but work in Safari. This has been tested on 5 computers that are connected to the site from different locations.

  • Thanks John,

    I didn’t think ACF_Form allowed this.

    I ended up writing a function to handle this for me.

  • Henry,

    Is this all of your code your using at the top of your template file?

    Jeff

  • James,

    Thanks for the help. I know it has been awhile, but after reloading the site from scratch this issue went away. Not sure what fixed it to be honest. Going to close this out.

    Jeff

  • Here’s what I did as a work around. I have to believe there is a more elegant way to do this, fewer db calls and such. I’ll have to research this in the future.

    Layout of the Entry Post Type:

    • ACF FORM (single-entry.php)
      1. Category One Field Group (Entry Post Type Selected in Admin)
      2. Category Two Field Group (Entry Post Type Selected in Admin)
      3. Category Three Field Group (Entry Post Type Selected in Admin)

    I took the field key from the first field in the Field Group and ran a prepare_field for each.

    add_filter('acf/prepare_field/key=field_58f8d36119412', 'format_entry_header');	// Category One Header
    

    When found, the prepare_field outputs a <div> with my Header Information. This in displayed before the Field and with a little CSS, looks good.

    echo '<h3 class="entry-form-title">Maintenance Factors</h3>';
    

    The drawback is that you can not have the fields in a tab or you will get the <div> at the bottom of the first tab AND where intended. Haven’t dug into this much more as I need a solution quickly.

    Not sure I should mark this as solved?

  • This reply has been marked as private.
  • Glad to help!

    Make sure you mark this as solved so others can benefit from what you came up with.

  • Aziz,

    Here is an option for your second question.

    I use the following code to disable a field if a user doesn’t need to see it. You make your logic use any of the WordPress functions to determine when are where to see it.

    
    add_filter('acf/prepare_field/name=record_number', 'disable_acf_prepare_field');
    
    function disable_acf_prepare_field( $field ) {
      		
            // Does the user have an Office role?
            $user = wp_get_current_user();
                   if ( in_array( 'office', (array) $user->roles ) ) {
    	              $usergroup = 'office';
                   }
    
    	switch($field['_name']) {	
    		// Which field are we looking for?	
    		case 'record_number':
                       if ($usergroup == 'office' {
    			      // Set the CLASS of the field to use css to hide
    			      $field['wrapper']['class'] = 'hide';
                       }
    		    break;
    		default:
                        break;
              	
    	}
    }
    
    return $field;
    
    }
    
    

    Then at the top of my php I include the following css style. Can be either added to the page template or some other theme css that is used for the page/post/post-type.

    <style>
    
    	.hideme {
    		
    		display: none;
    	}
    
    </style>

    Hope this helps.

    Jeff

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