Home Forums ACF PRO Simple Fields to ACF


Simple Fields to ACF

  • I’ve inherited a site built almost entirely on simple fields and I’m working on updating it to ACF PRO.

    I’m not experienced with PHP, (I’m an HTML, CSS guy!) so this is a major undertaking for me.

    Right now I’m working on the hero section, the current code looks something like this:

    $hero = simple_fields_fieldgroup('field-group');
    $hero_field = (!empty($hero['value']) ? $hero['value'] : '');
    $hero_field2 = (!empty($hero['value2']) ? $hero['value2'] : '');
    $hero_field3 = (!empty($hero['value3']) ? $hero['value3'] : '');
    //output follows

    It looks like simple_fields_fieldgroup() is calling the array in a field group and assigning each value to a variable and then outputting the variables in the theme.

    I want to avoid having to recode the entire site, if I can assign the the new ACF values to the current variables I think I would be able to simply add new custom fields using the same names and labels as the simple_fields.

    In this particular example would I be able to use the same variables by using the acf_get_field_groups() function?

  • I think I’ve got something working close to what I need:

    $hero = simple_fields_fieldgroup('field-group');
    $hero_field = (!empty($hero['value']) ? $hero['value'] : '');
    $hero_field =  (!empty($hero_field) ?: get_field('value'));

    I think this should allow me to continue the simple field architecture while I slowly make the switch over to ACF.

  • Hi @jorgepreble

    I’m afraid I’m not familiar with Simple Fields, so I’m sorry if I can’t help you much.

    I think your code looks OK, but please keep in mind that get_field('value') will get the value from a custom field with the name of “value”. This page should give you more idea about it:

    Thanks 🙂

  • @James,

    Thanks! This is the code that ended up working:

    $hero = simple_fields_fieldgroup('hero');
    if (!empty($hero['video'])) {
    	$hero_video = $hero['video'];
    } else if (empty($hero['video'])){
    	$hero_video = get_field('video');
    } else {
    	$hero_video = '';

    In simple fields first you have to call the field group array with simple_fields_fieldgroup()

    Then I checked to see if simple fields is being used in the current post, if not then we move on the ACF, else leave it blank.

    So far it works like a charm!

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

The topic ‘Simple Fields to ACF’ is closed to new replies.