0

Currently I have a field group defined using the ACF plugin, showing: title and icon and a link, on a specif area of my page. I want to give one of my Content Contributors the ability to choose from two different field groups for that same area of my page depending on their needs. Is this possible? If so how would I go about it doing? Thank you.

<h2 class="icon" style="background:url(<?php the_field('top_left_icon');?>) no-repeat left center;"><?php the_field('top_left_title');?></h2>
<?php the_field('top_left_text');?>

<?php if( (get_field('top_left_button_text')) && (get_field('top_left_button_link'))){?>
<a class="button" href="<?php the_field('top_left_button_link'); ?>"><?php the_field('top_left_button_text'); ?></a>
<?php } ?>

And here is a screen grab of what that looks like implemented in the ACF plugin admin side of things:

enter image description here

2
  • What code did you use for the custom fields? Feb 3, 2014 at 17:21
  • 1
    This seems extremely specific to plugin. Please elaborate on your implementation.
    – Rarst
    Feb 3, 2014 at 17:44

1 Answer 1

0

In order to achieve what I needed, I had to detect if any of the fields (in my case only 3 were necessary) were left empty. If any of them were empty, then the test failed and the "else" part of the code gets executed (the else part contains markup for the "alternate field group").

Here is my code:

<?php if( get_field('top_left_icon') && get_field('top_left_title') && get_field('top_left_text') !== '' ): ?>

<h2 class="calendar" style="background:url(<?php the_field('top_left_icon');?>) no-repeat left center;"><?php the_field('top_left_title');?></h2>
<?php the_field('top_left_text');?>

<?php if( (get_field('top_left_button_text')) && (get_field('top_left_button_link'))){?>
    <a class="button" href="<?php the_field('top_left_button_link'); ?>"><?php the_field('top_left_button_text'); ?></a>
<?php } ?>

In addition, I had to create an "alternate" field group in WordPress Admin area for my page. Hope this helps anybody that may have something similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.