
Hi @davelee
I think the reason this happens is because when you change the user role on the profile page, before saving, the users role hasn’t actually changed.
I understand your issue and I can see how it’d be troublesome in combination with required fields. I think it’s just about it being a scenario not previously anticipated and thus not taken into account for in the code.
I’ll talk to Elliot about this and we’ll see how to best approach it.

No problem!
Please mark the reply as an answer to your question to make it easier for future answer-searching folks π

This is absolutely possible to do and it’s really just a basic relationship querying and reverse querying.
These two different queries should get you going! If you need further extensive help you can contact me directly at [email protected] for help through our web agency.
//This should be in the loop
//Fetch an author post based on the current post authors (users) ID
$author_ID = get_the_author_meta('ID');
$args = array(
'post_type' => 'authors',
'meta_query' => array(
array(
'key' => 'userfieldname',
'value' => $author_ID,
'compare' => 'LIKE'
)
)
);
$author_query = new WP_Query($args);
//fetch all posts for the user. I'm not 100% sure the user field type returns an user object but I think so.
//It's also possible that $author is an array with user objects inside. if so change $author->ID to $author[0]->ID.
$author = get_field('userfieldname');
$args = array(
'post_type' => 'authors',
'author' => $author->ID
);
$usersposts_query = new WP_Query($args);

Hi @cliffordp
Thank you for the feedback! ACF is almost entirely maintained by Elliot Condon alone and as such he has quite a lot to do!
I can imagine that the date picker could be extended to also include time and timezones but I don’t think it can be given a high priority. There’s also the possibility to create your own field type for this like in the link you sent.
I will create a feature request for this but I can’t say when or if it’ll be implemented. Perhaps I give it a go myself at some point as I do think it’s a good extension if done right!

Hi @vegasmaster
How do you import/export the fields? With the provided tools?
If you’re using ACF Pro (5.x) you can make use of the ACF JSON feature to duplicate the fields for each of your separate installations. That way you can also easily just create new fields on one of the sites designated as the “main site” and copy the acf-json folder to each other installation by FTP, quick and easy π
http://www.advancedcustomfields.com/resources/local-json/
Hi Jonathan,
Thank you for your help.
Yes, the parent pages are not true WordPress category pages but regular pages that will display each of their child pages; sorry for the confusion.
I will be handing over this site to a client, and would prefer not to have them manually input a featured image each time they create a child page, but rather have one of several pre-loaded images display next to the child page name and description on the parent page.
The query_post code came from a post on selecting random repeater fields I came across β I am certainly open to other methods, but am just not sure how to achieve what I’m looking for. I also plan to remove my inline CSS β was just there for quick testing purposes.
Thank you!

Hi @joverbey,
There’s some clarification needed here.
First of it seems you’re not actually talking about category pages but rather regular pages in wordpress (you’re querying page post_type).
Second, why are you not simply putting these images in the respective child page? Maybe even as featured image since that seems to be what you want it to be used as.
Some other notes that may be good to know:
* Don’t use query_posts. You’ll only be messing with the main query in a bad way. Instead create a new query with wp_query. https://codex.wordpress.org/Class_Reference/WP_Query
* Try to avoid inline styling of elements. Put this in your style.css instead
img{ max-width: 100%; height: auto; }

Yeah π
It’s an easy function to miss as it looks so much alike the others. But I’m glad I could help! Be sure to really scan the available functions/actions/filters in the documentation before attempting something hacky, there’s actually quite a bit there!

damn it ^^. then one could use it that way:
<?php
if($fields = get_field_objects()){
unset($fields["bild"]);
unset($fields["asin"]);
unset($fields["preis"]);
unset($fields["bewertung"]);
unset($fields["produktname"]);
?>
<div class='data row'>
<?php
foreach($fields as $field){
?>
<div class='item col-sm-6 col-md-4 col-lg-3'>
<div class='term'>
<?php echo $field["label"];?>
</div>
<div class="value">
<?php
if(isset($field["prepend"])) echo $field["prepend"]." ";
if(isset($field["choices"])){
if(is_array($field["value"])){
$newarray = array();
foreach($field["value"] as $value){
$newarray[] = $field["choices"][$value];
}
echo implode(",",$newarray);
} else {
echo $field["choices"][$field["value"]];
}
} else {
echo $field["value"];
}
if(isset($field["append"])) echo " ".$field["append"];
?>
</div>
</div>
<?php
}
?>
</div>
<?php
}
?>
this will generate nice list with pre- and appended elements and will look for right labels for checkboxes/select fields
Thanks Elliot,
Well after a bunch of testing I finally found the main culprit.
First off, it seems that JSON does not have a speed advantage over PHP.
Not in my tests anyway. Which for me is good as I want stick with PHP.
However, I did test upgrading to ACF5 and that increased the Speed drastically.
Page load went from 15sec to 2sec.
So I started looking as to why.
it seems it mainly had to do with the “page-link” field.
In ACF4 this field prints out the Select field and all the options. This is normal, but because the client has a few hundred posts, few hundred pages, products, casestudies, etc. The Select dropdowns were outputing about 1,000 option fields. On Top of that we are using Flexible Content and therefore there can be quite a few “page-links” on the page. This was causing the post.php file to be 4.4mb. This was making the page load extremely slow. In ACF5 you have switched this out for an Ajax Dropdown. So no more thousands of options in select fields. This took the page size down to 974kb.
Even though this helped a lot I would suggest looking into ways to reduce the amount of markup. It seems something that my team can do is reduce the size of the key fields, but I would ask that you look into reducing the markup.
This seems quite long for an id:
id=”acf-field_52eda830feeb1-acfcloneindex-field_row_boxes_52f2da031b44e-acfcloneindex-field_row_boxes_10001″
I know it needs to be unique, but maybe you can hash it or something to reduce the size as this is also used in the “for” attribute. Maybe also look into reducing the amount of tags, white-space, etc.
To get around this issue in ACF4 you would need to change your “page-links” to “text” fields and have the client input the URL or have them input the Post ID. This is not ideal, but it would decrease the load on the page.
Because of this our team will look at incorporating ACF5 much sooner.
There are some minor issues with it like the new Dropdowns show the entire post title. My clients use really long titles. This makes the admin all wonky as items don’t line up. I am sure I can work around this with a CSS fix, but I will post this in another Thread.
Thanks
Also if anyone needs this info here is how I found converting PHP into JSON:
foreach (acf_get_local_field_groups() as $group)
{
$group['fields'] = acf_get_local_fields($group['key']);
echo json_encode($group, JSON_PRETTY_PRINT);
}
Hi,
If I write instructions without qtranslate tags (a simple normal text in one language) on front end it looks perfect.
The string which I’ve insert doesn’t have extra or converted chars.
so writing:
(name and number of street)
works as expected.
instead writing:
[:it](nome e numero della strada)[:en](name and number of street)[:fr](nom et numΓ©ro de la rue)[:]
won’t works.
I think is breaking something inside field rendering because I get this result when I do a print_r of the field:
Array
(
[ID] => 484
[key] => field_556d8c8ddc6bc
[label] => indirizzo
[name] => indirizzo
[prefix] =>
[type] => text
[value] =>
[menu_order] => 5
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 469
[wrapper] => Array
(
[width] =>
[class] =>
[id] =>
)
[_name] => indirizzo
[_input] =>
[_valid] => 1
[default_value] =>
[maxlength] =>
[placeholder] =>
[prepend] =>
[append] =>
[readonly] => 0
[disabled] => 0
)
but $field['instructions'] is not empty! It’s filled with:
[:it](nome e numero della strada)[:en](name and number of street)[:fr](nom et numΓ©ro de la rue)[:] and also $field['wrapper'] settings are lost
The really strange behavior is that:
if form is submitted (so after a POST request) it works as expected.
Array
(
[ID] => 484
[key] => field_556d8c8ddc6bc
[label] => indirizzo
[name] => indirizzo
[prefix] =>
[type] => text
[value] =>
[menu_order] => 5
[instructions] => (nome e numero della strada)
[required] => 1
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 469
[wrapper] => Array
(
[width] => 50
[class] =>
[id] =>
)
[_name] => indirizzo
[_input] =>
[_valid] => 1
[default_value] =>
[placeholder] =>
[prepend] =>
[append] =>
[maxlength] =>
[readonly] => 0
[disabled] => 0
)

If your still looking for help with this.
What is displayed on the front end for the instructions if you do not try to translate it? Do you see the string that’s supposed to be given to qtranslate? Is anything extra added, tags converted, for example: <' to '<, etc?

We need to do some debugging so that we can see what’s actually going on. The code you have looks like it should be working.
Alter your code to add the output statements I’ve added below and let me know what gets output
<?php if (have_rows('zichtbare_diensten')) :
$term_array = array();
while (have_rows('zichtbare_diensten')) : the_row();
$term_id = get_sub_field('zichtbare_diensten');
// display $term_id to see what it contains
echo '<br />TERM ID: '; var_dump($term_id);
$term = get_category($term_id);
// display $term and see what it contains
echo '<br />TERM: '; var_dump($term);
$term_name = $term->name;
array_push($term_array, $term);
endwhile;
endif;
?>
<?php if (get_row_layout() === 'diensten'): ?>
<div id="diensten-thumbs">
<?php foreach ($term_array as $row): ?>
<div class="dienst" style="background-image: url(<?php the_sub_field('image', $row->term_id) ?>)">
<h3><?php echo $row->name ?></h3>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
Hi John,
Thanks for your suggestion, but it isn’t working unfortunately.
This is my current code.
<?php if (get_row_layout() === 'diensten'): ?>
<div id="diensten-thumbs">
<?php foreach ($term_array as $row): ?>
<div class="dienst" style="background-image: url(<?php the_sub_field('image', 'category_'.$row->term_id) ?>)">
<h3><?php echo $row->name ?></h3>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
Any idea why I’m having problems with this John?
I’m getting all data in correctly but I want to change the order displayed. When I put the relationship lookup first, the awards data (award name/year/short description) disappears. I can make it appear this way using absolute positioning but it stuffs up when it comes to other devices.
!! I will get this relationshi/reverse relationship stuff worked out one day π
Thx
This is the order I want but cannot get
<?php $awards_query = new WP_Query( array( 'post_type' => 'awards', 'showposts' => 50, 'meta_key'=>'award_year', 'orderby' => 'meta_value_num' ) ); ?>
<?php while ($awards_query->have_posts()) : $awards_query->the_post(); ?>
<div class="vc_col-med-4 vc_col-lg-4 vc_col-sm-6 vc_col-xs-12 awards">
<?php foreach(get_field('project') as $post):
setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>" >
<?php the_post_thumbnail('awards', array( 'class' => 'award_img' ) ); ?></a>
<h3 class="award_project"><?php the_title(); ?></h3>
<?php endforeach; wp_reset_postdata(); ?>
<h2 class="award_name"><?php the_field('award_name'); ?> |
<?php the_field('award_year'); ?></h2>
<p><?php the_field('short_description'); ?></p>
</div><!--end cols -->
This is the work around I’m using with absolute positioning
<?php $awards_query = new WP_Query( array( 'post_type' => 'awards', 'showposts' => 50, 'meta_key'=>'award_year', 'orderby' => 'meta_value_num' ) ); ?>
<?php while ($awards_query->have_posts()) : $awards_query->the_post(); ?>
<div class="vc_col-med-4 vc_col-lg-4 vc_col-sm-6 vc_col-xs-12 awards">
<h2 class="award_name"><?php the_field('award_name'); ?> |
<?php the_field('award_year'); ?></h2>
<p><?php the_field('short_description'); ?></p>
<?php foreach(get_field('project') as $post):
setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>" >
<?php the_post_thumbnail('awards', array( 'class' => 'award_img' ) ); ?></a>
<h3 class="award_project"><?php the_title(); ?></h3>
<?php endforeach; wp_reset_postdata(); ?>
</div><!--end cols -->
Something along these lines:
<?php
$venue_active = the_field('display_wtr');
if ($venue_active == "Yes") {
?>
Output stuff here...
<?php
}
?>

Hi @soojooko
Thanks for the reply.
The flexible content field layouts should remain closed on page load, if they are staying open, perhaps there is a bug I am not aware of. Are you using ACF PRO, or ACF4 + add-on?
It sounds like you will require some sort of conditional logic without disabling the inputs.
You may be able to make use of some JS actions to prevent ACF from disabling the inputs. That way you can continue to use conditional logic without the original issue.
<script type="text/javascript">
(function($) {
acf.add_action('hide_field', function( $field, context ){
// bail early if not conditional logic (may be tab field)
if( context !== 'conditional_logic' ) {
return;
}
// maybe review $field name, key to avoid this on all fields?
// ...
// remove disable
$field.find('.acf-clhi').removeAttr('disabled');
});
})(jQuery);
</script>
Let me know if the above is confusing, basically, once added to the admin page, this will undo the ACF logic which disables inputs via conditional lgoic
Thanks
E
Ok, after a bit of time I see that when using PHP it doesn’t store any fields in the database. So we may have already been getting the benefits of not having to hit the database when using php. Which is good, but it doesn’t address the issue of the Admin still being slow when loading Fields, specifically Flexible Content.
So now the main question is:
If we have already only been using PHP to build our fields do we benefit from using JSON as well?
My initial thought is No, but we would need Elliot to confirm.
I may as well run some bench marks to determine that.
Also I have been playing with exporting fields from PHP to JSON.
I will have a follow up on that soon.
Thanks,
I am playing with ACF5 right now.
Looking at the JSON it looks almost identical to the PHP files.
So Here is the Big Question:
** Can’t you just load the fields with the PHP data instead of JSON ***
All that would be needed for us would be to specify a load type:
define(‘ACF_LOAD_TYPE’, ‘php’);
Default would be:
define(‘ACF_LOAD_TYPE’, ‘json’);
By setting it to ‘php’ we agree that ACF will not look at the database and instead only use what we have defined with php.
I’ve been able to isolate the snippet that cause the issue. The problem comes from the custom query.
Here is the code:
/**
* Filters posts by distance if URL parameters are set
*
* @param $query
* @return void
*/
function wpdf_filter( $query )
{
if ( Wpdf::validate_url_params() && Wpdf::is_enabled() ) {
global $wpdf_url_loc;
$loc = $wpdf_url_loc;
if ( $loc['lat'] != '' && $loc['lng'] != '' ) {
global $wpdf_orderString;
add_filter( 'posts_where', 'wpdf_filter_where' );
add_filter( 'posts_orderby', 'wpdf_filter_orderby' );
unset( $wpdf_orderString );
}
}
}
add_action( 'pre_get_posts', 'wpdf_filter' );
/**
* Filter for where
*
* @param $query
* @return string
*/
function wpdf_filter_where( $where )
{
global $wpdb, $wpdf_orderString;
$validPosts = array();
$orderStrings = array();
$queryStrings = array();
global $wpdf_url_loc;
$loc = $wpdf_url_loc;
$posts = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'lat' OR meta_key = 'lng' ORDER BY post_id" );
for ( $i = 0; $i < count( $posts ); $i += 2 ) {
$dis = Wpdf::distance( $posts[$i]->meta_value, $posts[$i + 1]->meta_value, $loc['lat'], $loc['lng'] );
$rad = Wpdf::get_rad();
if ( ( isset($_GET[$rad] ) && $dis < $_GET[$rad] ) || ! isset( $_GET[$rad] ) ) {
array_push( $queryStrings, 'wp_posts.ID = '.$posts[$i]->post_id );
array_push( $validPosts, array( 'distance' => number_format( $dis, 2 ), 'ID' => $posts[$i]->post_id ) );
}
}
usort( $validPosts, 'wpdf_compare' );
foreach ( $validPosts as $index => $validPost ) {
if ( intval( $index ) == count( $validPosts ) - 1 ) {
array_push( $orderStrings, 'ELSE '.$index );
} else {
array_push( $orderStrings, "WHEN '".$validPost['ID']."' THEN ".$index );
}
}
$queryString = ' AND (' . implode( ' OR ', $queryStrings ) . ')';
if ( count( $validPosts ) > 1 ) {
$wpdf_orderString = ' CASE wp_posts.ID ' . implode( ' ', $orderStrings ) . ' END';
} else {
$wpdf_orderString = '';
}
return $where . $queryString;
}
/**
* Filter for orderby
*
* @param $query
* @return string
*/
function wpdf_filter_orderby( $orderby )
{
global $wpdb, $wpdf_orderString;
return $wpdf_orderString;
}
/**
* Associate array comparison
*
* @param query
* @return positive/negative
*/
function wpdf_compare( $a, $b )
{
return $a['distance'] == $b['distance'] ? 0 : ($a['distance'] < $b['distance']) ? -1 : 1;
}
There is obviously something in this part of code that cause the problem, but I can’t figure what…
PS: I’m aware that my problem is not directly related to ACF in itself, but I don’t know where to ask for help. thanks in advance π

Hi Jason,
I actually think you can make this a lot easier on yourself.
Instead of having three queries (inside an empty and completely unnecessary loop) you can probably do a single query and order the results based on your meta data. Luckily in the alphabet it goes L – M – S π
Here’s a very refactored code I think should do the trick for you (you might need to set the order parameter too). I haven’t tested this live.
<section id="content">
<section id="featured">
<div class="row">
<?php
// args
$args = array(
'post_type' => 'post',
'meta_key' => 'homepage_size',
'orderby' => 'meta_value',
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$size = get_field('homepage_size');
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
$image_style = ( $image ? "background-image: url('" . $image[0] . ");" : '' );
if( $size === 'large' ){
$classes = 'col-md-6 col-sm-6 col-xs-12 post featured-' . $size;
}else if( $size === 'medium' ){
$classes = 'col-md-6 col-sm-6 col-xs-12 post featured-' . $size;
}else{
$classes = 'col-md-3 col-sm-3 col-xs-12 post featured-' . $size;
}
?>
<div class="<?php echo $classes; ?>" style="<?php echo $image_style; ?>">
<div class="post-content">
<div class="category">
<?php $categories = get_the_category(); foreach($categories as $category) { $cat_name = $category->name; if($cat_name != 'featured') echo '<a href="'.get_category_link($category->term_id).'">'.$cat_name . '</a> '; } ?>
</div>
<div class="clearfix"></div>
<header class="title">
<a href="<?php the_permalink(); ?>">
<h1><?php the_title(); ?></h1>
<h2><?php the_field('subtitle'); ?></h2>
</a>
</header>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); // Restore global post data stomped by the_post(). ?>
</div>
</section>
</section>

Hello everyone,
I’ve come across the need for RGBA myself too at times so I’m with you there.
@herrfischer s link to a third party plugin should do well until this is implemented. As far as implementation goes it’s not as easy as you would think.
ACF is using WordPress Core Color picker called Iris. Iris supports many different color types (?) but unfortunately not RGBA (it does support RGB tho).
There’s a lot of requests for this feature on Iris github repo (https://github.com/Automattic/Iris) but so far the author has yet to implement it and doesn’t seem to like the forks people have done. So to support this in ACF Elliot would either have to switch to a different color picker (meaning another script to load in admin) or wait for it to be implemented in core.
I would suggest using the third party plugin until then π
Hi @jonathan!
Thanks for your help.
That is what I had in mind and I did look at “acf-pro-input.js” trying to understand how to trigger the click.
I’ve tried this in the console for a quick test but no rows are added
jQuery('.acf-repeater-add-row').trigger('click')
Thoughts?

No problem @cdiscla
glad it worked out fine! I hope it’s just formatting of the posting that makes your end quotation mark different (it would probably break the code).

Hi @bmds,
Since localstorage is Javascript-based you don’t really have much choice but to read the localstorage data and create new rows and insert the values.
Since it’ll be very hard for you to replicate how the rows are structured I’d recommend just triggering the “add row” button with JS thus letting ACF do the creation.
Something like:
jQuery('.acf-repeater-add-row').trigger('click', function(){
//Delay a function a few hundred millseconds to give ACF time to create the row then do your own insertion. Preferably via function call
setTimeout(insertLocalstorageData,500)
});
function insertLocalstorageData(){
//Do stuff!
}
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.