
I can understand your frustrations a bit, but I can also guess to some degree the developer’s thinking is that it works consistent with the way update_post_meta() works and update_field() is just a wrapper for update_post_meta().
Returns meta_id if the meta doesn’t exist, otherwise returns true on success and false on failure. NOTE: If the meta_value passed to this function is the same as the value that is already in the database, this function returns false.
Maybe when he gets time he’ll add it to the documentation. I’m also assuming that since update_field() does not mention returned values that it’s not expected that anyone would be testing the returned value. The function is not going to “Fail”, after it is called the field value for the post_id will be set to you want to update it to, one way or another.

This weekend I started looking at the available plugins for reusable field groups. Testing and research turned into an entire weekend and at the end I had created my own version of a reusable field group field.
It works a bit differently than the others, it works by rebuilding field groups that include a reusable field group field ans local field groups which override the original field groups. This only works in ACF5, ACF4 does not support acf_local().
I have not completely tested it and would be interested in feedback or bug reports. I’ll also answer question. There’s not documentation yet, mostly because I think that the instructions when creating the field are pretty self explanatory.
https://github.com/Hube2/acf-reusable-field-group-field

This weekend I started looking at the available plugins for reusable field groups. Testing and research turned into an entire weekend and at the end I had created my own version of a reusable field group field.
It works a bit differently than the others, it works by rebuilding field groups that include a reusable field group field ans local field groups which override the original field groups. This only works in ACF5, ACF4 does not support acf_local().
I have not completely tested it and would be interested in feedback or bug reports. I’ll also answer question. There’s not documentation yet, mostly because I think that the instructions when creating the field are pretty self explanatory.
https://github.com/Hube2/acf-reusable-field-group-field

This weekend I started looking at the available plugins for reusable field groups. Testing and research turned into an entire weekend and at the end I had created my own version of a reusable field group field.
It works a bit differently than the others, it works by rebuilding field groups that include a reusable field group field ans local field groups which override the original field groups. This only works in ACF5, ACF4 does not support acf_local().
I have not completely tested it and would be interested in feedback or bug reports. I’ll also answer question. There’s not documentation yet, mostly because I think that the instructions when creating the field are pretty self explanatory.
https://github.com/Hube2/acf-reusable-field-group-field

This weekend I started looking at the available plugins for reusable field groups. Testing and research turned into an entire weekend and at the end I had created my own version of a reusable field group field.
It works a bit differently than the others, it works by rebuilding field groups that include a reusable field group field ans local field groups which override the original field groups. This only works in ACF5, ACF4 does not support acf_local().
I have not completely tested it and would be interested in feedback or bug reports. I’ll also answer question. There’s not documentation yet, mostly because I think that the instructions when creating the field are pretty self explanatory.
https://github.com/Hube2/acf-reusable-field-group-field

This weekend I started looking at the available plugins for reusable field groups. Testing and research turned into an entire weekend and at the end I had created my own version of a reusable field group field.
It works a bit differently than the others, it works by rebuilding field groups that include a reusable field group field ans local field groups which override the original field groups. This only works in ACF5, ACF4 does not support acf_local().
I have not completely tested it and would be interested in feedback or bug reports. I’ll also answer question. There’s not documentation yet, mostly because I think that the instructions when creating the field are pretty self explanatory.
https://github.com/Hube2/acf-reusable-field-group-field

I started looking into making a reusable field group field after my last comment. Testing and research turned into an entire weekend and at the end I had created my own version of a reusable field group field.
It only works with ACF5. It works by rebuilding field groups that include a reusable field group field ans local field groups which override the original field groups. The reason it only works with ACF5 is that acf_local() is not available before 5.
I have not completely tested it and would be interested in feedback or bug reports. I’ll also answer question. There’s not documentation yet, mostly because I think that the instructions when creating the field are pretty self explanatory.
https://github.com/Hube2/acf-reusable-field-group-field

Cool! Yeah the post object is much easier to manipulate if you only require one..
Since ACF started to use select2 for the dropdowns it’s just as easy to use as the relationship field.. (earlier on I used to utilize relationship field even if I only needed 1 due to the interface).
Best of luck in your project!

Hey!
So you’re sort of twisting and turning the query around. You start off with terms which you use to query posts which then are used to show terms.
Your code is a bit confusing.. I’ll post a cleaned up version here but first I want to talk about what it does.
So with the current code you fetch ALL terms in the taxonomy systemcontents_category2. You then loop through each term and perform a wp_query which fetches all posts connected to that term.
Then you loop through each post and output the terms name and some information from the post.
Nowhere is $selected being used and I don’t quite get what it is you want to use it for either. You should also be using ACFs API functions like get_field() to fetch the meta values for the post.
If this is not what you need please try to explain further and possibly include a screenshot of your ACF setup.
<?php
$member_group_terms = get_terms('systemcontents_category2');
$selected = get_sub_field('system_contents_posts');
?>
<?php foreach ( $member_group_terms as $member_group_term ) endforeach; ?>
<?php
$args = array(
'post_type' => 'pj_systemcontents2',
'posts_per_page' => 400, //unlikely high
'tax_query' => array(
array(
'taxonomy' => 'systemcontents_category2',
'field' => 'slug',
'terms' => array( $member_group_term->slug ),
'operator' => 'IN'
)
)
);
$member_group_query = new WP_Query($args);
?>
<?php if ( $member_group_query->have_posts() ) : ?>
<h3><?php echo $member_group_term->name; ?></h3>
<?php while ( $member_group_query->have_posts() ) : $member_group_query->the_post(); ?>
<?php echo get_field('document-section'); ?>
<?php echo get_field('document-reference') . ' ' . get_field('document-sub-section'); ?>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
<?php endforeach; ?>

what happens to the data I’ve entered into the field for these pages if I change the location rule to display on posts instead of pages? Is this data still taking space up on the database?
Yes, the data that was added for posts will still be there.
Do I have to delete all the field information from the pages before changing the rule so I don’t end up with data I don’t want in the database?
Deleting what’s in all the fields first won’t do anything except remove the content. The empty content will still be in the database. There isn’t any way to delete the fields completely when you change the locations except to go into the database and do it manually.
It’s a good idea to plan the development of a site so that once data is entered it does not need to be removed. I think there is a plugin that will convert the post type of a post in WP, in this case you could change your pages to posts and data in the fields will go with it.
Thanks, John. That document was helpful.
For someone else who may stumble across this article and find my query helpful, here it is:
$my_query = new WP_Query(array(
'category_name' => 'artist',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
'gender_clause' => array(
'key' => 'gender',
'value' => 'f',
),
'sort_clause' => array(
'key' => 'sort_name',
'compare' => 'EXISTS',
),
),
'orderby' => 'sort_clause',
'order' => 'ASC',
));
Basically, I am querying posts of the ‘artist’ category, and then selecting those posts where the ‘gender’ (a custom field I have setup) is set to the value of ‘f’. There is another custom field called ‘sort_name’ that I use to order the posts by.

Yes, you will need to add a meta_query to do this.
There was a new feature added in WP4.2 that would allow you to do this.
And you’ll need to query by the field you are ordering by as well. See the city_clause example.
https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

There is a filter, it can be used in some cases but the results can be broken in other cases. The only thing you can do is try it and see if it works.
http://www.advancedcustomfields.com/resources/acf-fields-relationship-query/
I know that if the relationship is for a hierarchical post type, changing the orderby value breaks the results because ACF groups them by parent. There may be other issues that I’m not aware of as well.

I’m still not exactly sure what you are doing?
What template you’re using to display this?
Can you go over again what you’re trying to show on the page?
If you’re create a catagory named ‘meps_category’ then you can create a template file names `taxonomy-meps_category.php’, have you done this?
I you do this then you can get the current category and then get only children of that category.
$queried_object = get_queried_object();
$terms = get_terms(get_terms(
'meps_category', array(
'parent' => $queried_object->term_id
));

Yes, I’ve actually used this idea to build a site, we called them panels. The client can create a panel with 1, 2, 3 or 4 columns and specify much of the formatting used. The main content area is removed on these pages.
The main problem is that the standard WP search will not search this content. You need to install something like https://wordpress.org/plugins/search-everything/
One other thing that you may run into is the admin timing out if too many content areas are added. On another site I built I the client has up to 7 content areas for each section plus quite a few fields that control the layout of these fields on the front end. At about 10 sections using all of the available content areas for them (70 wysiwyg fields) the admin might time out when they save the page.

That depends on if you’re allowing only one post type and if that post type is hierarchical or not.
If you you’re allowing multiple posts types or the post type is hierarchical, then no. The reason is that ACF groups the posts according to post type and parent page. Attempting to reorder them by date will cause the results to be broken.
If you are limiting it to a single post type and it is not hierarchical then the answer is a definite maybe. There are filters that you can use set the WP_Query args and you can change the order by.
Line 144 of /fields/page_link.php, I don’t think these filters are documented.
// filters
$args = apply_filters('acf/fields/page_link/query', $args, $field, $options['post_id']);
$args = apply_filters('acf/fields/page_link/query/name=' . $field['name'], $args, $field, $options['post_id'] );
$args = apply_filters('acf/fields/page_link/query/key=' . $field['key'], $args, $field, $options['post_id'] );
I have not tested this.
add_filter('acf/fields/page_link/query/name=FIELD_NAME',
'change_page_link_order_by', 10, 3);
function change_page_link_order_by($args, $field, $post_id) {
$args['orderby'] = 'date';
$arge['order'] = 'DESC';
return $args;
}
John,
I tried your code a few times and it produced the same results. I still had to update twice to get it working.
I’m not knowledgeable on how to update the code to make it work. Should the $value to be equal to something?
Thanks

okay. that was easy! here we go. simply adjust it to your needs:
1. create a new entry in wp_options: “is_winner”
2. insert that code to your functions.php:
// register the meta box
add_action( 'add_meta_boxes', 'my_custom_field_checkboxes' );
function my_custom_field_checkboxes() {
add_meta_box(
'winner_box', // this is HTML id of the box on edit screen
'Winner', // title of the box
'my_customfield_box_content', // function to be called to display the checkboxes, see the function below
'product', // on which edit screen the box should appear
'side', // part of page where the box should appear
'default' // priority of the box
);
}
// display the metabox
function my_customfield_box_content( $post_id ) {
wp_nonce_field( 'wp_nonce_check', 'myplugin_nonce' );
echo '<label><input type="checkbox" name="is_winner" value="1" /> Winner';
if(get_the_id() == get_option("is_winner")) echo " (currently selected)";
echo "</label>";
}
// save data from checkboxes
add_action( 'save_post', 'my_custom_field_data' );
function my_custom_field_data() {
// check if this isn't an auto save
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// security check
if ( ! isset( $_POST['myplugin_nonce'] ) || !wp_verify_nonce( $_POST['myplugin_nonce'], 'wp_nonce_check' ) )
return;
if ( isset( $_POST['is_winner'] ) )
update_option("is_winner", get_the_id());
else
return;
}
now in every post is a meta box along with ACF fields. when you check that meta box, the id is saved to the field in wp_options. this way, you save a lot of performance because there is no wp_query and you do not need to alter all posts!!
Got it working!
There’s no need to use this $image_thumb = $icon['sizes']['full'];
Just echo $icon and Return Value should be Image URL nor Image Object.
Thanks again Jonathan for help.
<?php
$current_term = get_queried_object();
$args = array(
'parent' => $current_term->term_id,
'orderby' => 'slug',
'hide_empty' => false
);
$child_terms = get_terms( $current_term->taxonomy, $args );
?>
<ul>
<?php foreach ($child_terms as $term) { ?>
<?php
$icon = get_field('icon', $term->taxonomy . '_' . $term->term_id);
?>
<li>
<h3><a href="<?php echo get_term_link( $term->name, $term->taxonomy ); ?>"><?php echo $term->name; ?></a></h3>
<img src="<?php echo $icon; ?>" class="icona" alt="" />
</li>
<?php } ?>
</ul>
Hi, I still can’t make it work. But I have something that maybe will help to solve the problem.
If for Return Value (Specify the returned value on front end) I choose Image URL and there’s an image for this term than in the source I can see:
<img src="h" class="icon" alt="" />
If there’s no image for this term there’s nothing in src.
I think I spoke to soon.. Its 99% there.. I seem to have an issue now which is rather frustrating… I’m getting them to display correctly.. but now when I look in different categories (I have set up 2 different categories), i’m getting both the child categories display… even though they are from different parent categories..
http://whyttip.eu/index.php/meps/bulgaria/
http://whyttip.eu/index.php/meps/belgium/
password: ecr_group
for some strange reason they are both displaying even though one sub category (Bulgaria Without Censorship (България без цензура)) is for Bugaria and the other (New Flemish Alliance (Nieuw-Vlaamse Alliantie)) is for Belgium.
The code i’m using is below. Can anyone help me work this out?
<div class="blog-default">
<div class="master_container container">
<section class="page_content col-xs-12 col-md-12">
<div class="blog-default-bg">
<h2>YOUR MEPS</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla fringilla, orci ut mattis lacinia, enim risus hendrerit ante, fringilla fringilla turpis diam efficitur lectus. Donec sagittis, quam a pellentesque dictum, odio sapien porta eros, eget cursus nibh orci nec purus. Curabitur blandit tincidunt blandit. Morbi fermentum urna sed lacus condimentum scelerisque. Nunc vitae mauris sit amet lectus euismod accumsan.</p>
<form id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
<input class="inlineSearch" type="text" name="s" placeholder="Search" onblur="if (this.value == '') {this.value = 'Search';}" onfocus="if (this.value == 'Search') {this.value = '';}" />
<input type="hidden" name="post_type" value="mep" />
<?php wp_dropdown_categories( 'show_option_none=Select Country&show_count=1&hierarchical=1&taxonomy=meps_category&depth=1' ); ?>
<?php wp_dropdown_categories( 'show_option_none=Select Group&show_count=1&hierarchical=0&taxonomy=meps_category&depth=1' ); ?>
<input class="inlineSubmit" id="searchsubmit" type="submit" alt="Submit" value="Submit" />
</form>
<br/>
<?php $currentCat = $_GET['cat'];?>
<?php $loop = new WP_Query(array('post_type'=>'mep', 'cat'=>$currentCat, 'order' => 'asc')); ?>
<strong><?php echo single_cat_title();?> - Groups and MEPs:</strong>
<div class="clear"></div>
<br/>
<div id="accordion" class="panel-group">
<div class="panel panel-default">
<!-- SUB CATEGORY TITLE AREA -->
<?php
$member_group_terms = get_terms( 'meps_category', array(
'child_of' => $currentCat,
'hierarchical' => false
) );
?>
<?php
foreach ( $member_group_terms as $member_group_term ) {
$member_group_query = new WP_Query( array(
'post_type' => 'mep',
'tax_query' => array(
array(
'taxonomy' => 'meps_category',
'field' => 'slug',
'terms' => array( $member_group_term->slug ),
'operator' => 'IN'
)
)
)
);?>
<div class="panel-heading">
<!--<div class="col-md-2"><img src="#" /></div>-->
<div class="col-md-12"><h3><?php echo $member_group_term->name; ?></h3>
<p><?php echo $member_group_term->description; ?></p></div>
<div class="clear bottomgap"></div>
<div class="col-md-8"></div><div class="col-md-4"><a data-toggle="collapse" data-parent="#accordion" class="button" href="#<?php echo $member_group_term->term_id; ?>">View MEPs</a> <a href="<?php echo $member_group_term->mep_party_link; ?>" class="button" target="_blank">Visit Website</a></div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<!-- END SUB CATEGORY TITLE AREA -->
<div id="<?php echo $member_group_term->term_id; ?>" class="panel-collapse collapse col-md-12">
<!-- SUB CATEGORY POSTS AREA -->
<?php if ( $member_group_query->have_posts() ) : ?>
<?php while ( $member_group_query->have_posts() ) : $member_group_query->the_post(); ?>
<div class="panel-body">
<div class="col-md-2 meppic"><?php the_post_thumbnail(); ?></div>
<div class="col-md-10"><h3 class="mepname"><?php echo the_title();?></h3>
<strong><?php the_field('title_position'); ?></strong>
<div class="clear"></div>
<?php the_field('location'); ?>
<div class="clear"></div>
<br/>
<?php the_field('description'); ?>
<div class="clear"></div>
<br/>
<div class="mepdetails"><div class="col-md-3 first"><strong>Email:</strong> <a href="mailto:<?php the_field('email'); ?>"><?php the_field('email'); ?></a></div><div class="col-md-3"><strong>Website:</strong> <a href="http://<?php the_field('website'); ?>" target="_blank"><?php the_field('website'); ?></a></div><div class="col-md-3"><strong>Tel:</strong> <?php the_field('tel'); ?></div><div class="col-md-3 last"><a href="http://www.twitter.com/<?php the_field('twitter_id'); ?>" target="_blank"><?php the_field('twitter_id'); ?></a></div></div>
</div>
</div>
<!-- END SUB CATEGORY POSTS AREA -->
<?php
endwhile;
?>
</div>
<?php endif; ?>
<?php
// Reset things, for good measure
$member_group_query = null;
wp_reset_postdata();
}
?>
</div>
</div>
</div>
</section>
</div>
</div>
Hi John,
Well, after a couple of hours wondering why your perfectly logical code wasn’t working, it turns out that my client is still using ACF4 and I just assumed (yup, I’m an ass) it was v5.
So, anyway, until they’re happy to upgrade to v5 here’s my working v4 code which is very similar to yours – the main difference being the apply_filters on line 3:
$groupID = 92;
$fields = array();
$fields = apply_filters('acf/field_group/get_fields', $fields, $groupID);
if($fields) {
foreach( $fields as $field) {
if ($field['type'] == 'email') {
echo "<li>" . $field['label'] . "</li>";
}
}
}
Thanks for your help, it definitely made things a lot easier.
Hi John,
EDIT: I should’ve specified, all this action should happen inside functions.php, not on the front end of the site.
Thanks for your reply but no – its nothing to do with users I just want to get the value of the name attribute of every field that is an email type field from a certain Field Group.
So I have a Field Group I’ve called ‘Additional Fields for User Profile’ which is – as the name suggests – some extra fields for the User Profile page. Some of these are email fields with their Field Type set to ’email’ – what I want to do is get the value of the name attribute of every field that has a type of email so:
<input id="acf-field-contact_email" class="email" name="fields[field_52e10709850b3]" value="[email protected]" placeholder="" type="email">
for this field (which has a type of email) I need to get the value: fields[field_52e10709850b3] from the name attribute.
Thanks
Hi Jonathan
I have solved this, I am loving this ACF.
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
<?php if ( have_rows('repeater', 'option') ) {
while ( have_rows('repeater', 'option') ) : the_row();
$image = get_sub_field('repeater_subfield1', 'option' );
endwhile;
if($image) {
?>
<li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<?php } } ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">Home Text</div>
<div role="tabpanel" class="tab-pane" id="profile">
<?php while ( have_rows('repeater', 'option') ) : the_row(); ?>
<div class="col-sm-2 col-xs-6 color_showcase text-center">
<img src="<?php the_sub_field('repeater_subfield1'); ?>" alt="">
<?php the_sub_field('repeater_subfield2'); ?>
</div>
<?php endwhile; ?>
</div>
</div>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.