
Hi @tatemz
The problem is that the replacement HTML coming back from the AJAX is not recognized by ACF. This is why it is not styled correctly / interacts correctly.
You will need to re initialize the ACF javascript on the HTML. You can do this quite easily by running a jQuery action on the new DOM element like so:
$(document).trigger('acf/setup_fields', $('#new-element'));

You betcha! If you check out the “Forum Topics Started” page for a user ( /forums/users/emcniece/topics/ in my case ) we can see the title of the topic, the number of comments, the forum that the topic is placed within, and the last reply time along with the fancy circle status indicator. Since the title of the topic links directly to the full topic view, it’s easy to access these forum topics.
When users are on the “Replies Created” page ( /forums/users/emcniece/replies/ in my case) there is no link to the parent topic – it only shows the user avatar, user name, timestamp and reply text. There does not seem to be any convenient method of jumping to the full thread that each reply belongs to!
Do you think it would be a good idea to place a topic link in the “Forum Replies Created” page for each of the replies listed so that we can easily jump to each particular topic?
Hi. I not use that plugin. My way to include maps is by using pure google api code…
Put in some place of your php file the script file:
<script>
function initialize(){
var place = new google.maps.LatLng(<?php the_field('coordinates');?>);
var mapOptions = {zoom:2,center:place,streetViewControl:false,mapTypeControl:false,mapTypeId:google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById('map'),mapOptions);
var marker = new google.maps.Marker({position:place,map:map,title:"<?php the_field('mapdesc');?>"});
}
function loadScript(){var script = document.createElement('script');script.type = 'text/javascript';script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' + 'callback=initialize';document.body.appendChild(script);}
window.onload = loadScript;
</script>
Explain:
■ var place = new google.maps.LatLng(<?php the_field('coordinates');?>);
Here the script will determinate where to place the map, so the LatLang as the name means read the Latitude and Longitude that you put there and create a place where later the map will be centered there.
So I create a text field with name coordinates with the coords of my desired place.
■ new google.maps.Marker({position:place,map:map,title:"<?php the_field('mapdesc');?>"});
More customization. Text field with place description (“mapdesc”). Optional.
■ document.getElementById('map')
Here the script is searching throught all the dom looking for an element with id “map”. So in some place of your code, put an div element with id map like this:
<div id="map"></div>
■ Remember to style de map element. Give a certain height and width by css if necessary.
This always works for me and here you have the Google Maps Javascript API v3, for more tricks and customization: https://developers.google.com/maps/documentation/javascript/
Hope I help!

Hi @emcniece
Sorry mate, I’m not following your question.
Perhaps you can give it some more context?

Hi @Sour Mash Steve
Thanks for the quesiton. Can you please test the difference between a WYSIWYG field and the native the_content?
Do both values on the front end render the same? Or is ACF adding extra p tags?
Ah-ah, I found a workaround. I just noticed now that the ACF relationship docs have a second option that doesn’t set postdata: http://www.advancedcustomfields.com/resources/field-types/relationship/
/*
* Loop through post objects ( don't setup postdata )
* Using this method, the $post object is never changed so all functions need a seccond parameter of the post ID in question.
*/
$posts = get_field('relationship');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $post_object): ?>
<li>
<a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID); ?></a>
<span>Post Object Custom Field: <?php the_field('field_name', $post_object->ID); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php endif;
This helps me avoid the situation!
So i’m guessing it’s the following 2 field calls that are failing?
<?php the_field("presentation_abstract"); ?>
<p>
<a href="<?php the_field("presentation_download_file"); ?>" target="_blank" class="arrow">Download</a>
</p>
</section>
If this is the case then a work around would be simple, set those fields as variables further up the page, and then simply call the variable.
<!-------------------MAIN PAGE LOOP------------------------->
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="main" class="clearfix">
<?php if(trim(get_field("headline_override")) != ""): ?>
<h1><?php the_field("headline_override"); ?></h1>
<?php else: ?>
<h1><?php the_title(); ?></h1>
<?php endif; ?>
<article>
<?php the_content(); ?>
<div id="presentations">
<!-------------------CUSTOM WP_QUERY LOOP------------------------->
<?php
// The Query
$args = array(
'post_type' => 'presentations',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'presentation_date',
'post_status' => 'publish',
'meta_key' => 'presentation_date',
'meta_query' => array(
array(
'key' => 'archived_presentation',
'value' => 'true',
'compare' => '!='
)
)
);
$custom_loop = new WP_Query($args);
#echo $custom_loop->request;
$previous_year = "";
// The Loop
if( $custom_loop->have_posts() ): ?>
<?php while( $custom_loop->have_posts() ): $custom_loop->the_post(); ?>
<?php
$date = DateTime::createFromFormat('Ymd', get_field('presentation_date'));
$current_year = $date->format('Y');
if($previous_year != $current_year) { echo "<p>" . $current_year . "</p>";}
$previous_year = $current_year;
?>
<section>
<h2><a href="<?php the_field("presentation_download_file"); ?>" target="_blank"><?php the_title(); ?></a></h2>
<?php $presentationDownloadFile = get_field("presentation_download_file");
$presentationAbstract = get_field("presentation_abstract"); ?>
<p>
<!-------------------FIRST ACF RELATIONSHIP LOOP THAT BREAKS THINGS------------------------->
<?php
#--------- research center
$posts = get_field('research_center');
if( $posts ):
foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<strong>Lead Research Center:</strong> <a href="/about/#center-<?php echo $post->ID; ?>"><?php the_title(); ?></a><br />
<?php endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif;
#--------- presenters
$posts = get_field('presenters');
if( $posts ): ?>
<strong>Presenter(s):</strong>
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<a href="/about/staff/#staff-<?php echo $post->ID; ?>"><?php the_title(); ?></a>
<?php endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif;
?>
</p>
<?php echo $presentationAbstract; ?>
<p>
<a href="<?php echo $presentationDownloadFile; ?>" target="_blank" class="arrow">Download</a>
</p>
</section>
<?php endwhile; ?>
<?php endif;
// Reset Query
wp_reset_postdata(); ?>
</div><!-- / #presentations -->
</article><!-- article -->
</div>
</div>
<?php endwhile; ?>
p.s. I don’t really get what you are trying to do so I can’t comment on whether the nested loops are required or not, but I think for single pages your first loop shouldn’t be required. I might be wrong though 😉
First off, the_field is used to echo a field’s contents, get_field is used to retrieve the fields data into into a variable, or in your case, can be used in an if statement. You also have a semi-colon after an if statement which is invalid and an empty else may had well just be removed. I’ve tied up your code a bit, give it a try.
<?php
$dlMaterials = get_field('downloadable_material');
if($dlMaterials) { ?>
<div class="material">
<h4>Supplemental Material:</h4>
<a href="<?php echo $dlMaterials; ?>"><i class="icon-download-alt"></i> - Download Supplemental Material</a>
</div>
<?php } ?>
<?php
$linksResources = get_field('links_and_resources');
if($linksResources) { ?>
<h4>Resources:</h4>
<p><?php echo $linksResources; ?></p>
<?php } ?>

What action is your AJAX request calling? I’m guessing you’ll just need to pass the ‘minvalue’, ‘maxvalue’, and post ID (i.e. via $_POST) to some custom handler function, for example:
function handle_slider_min_max() {
$post_id = $_POST['post_id'];
$min = $_POST['minvalue'];
$max = $_POST['maxvalue'];
update_field('slider_field_min', $min, $post_id);
update_field('slider_field_max', $max, $post_id);
}
// user logged in
add_action('wp_ajax_handle_slider_min_max', 'handle_slider_min_max');
// user not logged in
add_action('wp_ajax_nopriv_handle_slider_min_max', 'go_away');
Note: you should use the field key in update_field(), rather than specifying it by name.
Also, ‘go_away’ is not a native WP function (although it should be).

In addition to Elliot’s suggested method, if you didn’t want to change the value saved to the database, you could use the DateTime ‘format’ method:
$date = get_field("my_date_field");
// assuming your return format is "Ymd"
$dateTime = DateTime::createFromFormat("Ymd", $date);
if ( is_object($dateTime) ) {
$month = $dateTime->format('F');
$year = $dateTime->format('Y');
//...
}

ACF does have a method to load fields from code using “Export as PHP”. However, this does require that the fields are first created using the GUI, then exported, deleted via GUI, and included via PHP file… got me thinking about an “ACF field generator” which would basically be a web-based version of the GUI that outputs PHP code (like generatewp.com but for ACF). Of course, then there’s always the issue of name conflicts, incompatibility with custom field types, etc…

A quick snippet for you:
add_action( 'pre_get_posts', 'filtre');
function filtre($query) {
//echo '<pre>'.print_r($query->query_vars['post_type'], true).'</pre>';
switch($query->query_vars['post_type']){
case 'attachment': // Media library
if( current_user_can('manage_own_media') ) $query->set('author', get_current_user_id() );
break;
case 'post': // Posts
if( current_user_can('manage_own_posts') ) $query->set('author', get_current_user_id() );
break;
case 'page': // Pages
if( current_user_can('manage_own_pages') ) $query->set('author', get_current_user_id() );
break;
} // switch post_type
return $query;
}
Of course this is assuming that there are custom permissions set up using the User Role Editor!
Yes, this works for me. The cache made me crazy!
add_action( 'pre_get_posts', 'filtre');
function filtre($query) {
global $user_ID;
//global $current_user;
if( !is_admin() ) {
$query->set('author', $user_ID);
//$query->set('author',$current_user->id);
}
return $query;
}
Now I’m gonna try to filter the media, taxonomies and ACF. Will see if there’s a problems!
It seems was a cache problem!!
And to continue with the restriction.
What about filter the media?
Something like this, but not working yet
function ik_eyes_only( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
if ( !current_user_can( 'level_5' ) ){
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'ik_eyes_only' );
Thanks a lot!
I’m trying now.
user1 -> user_id=3
user2 -> user_id=5
Have you create a CPT row with user1, and log into with user2, and you don’t see the CPT row?
Did you mean this?
$query->set('author', 5);
Or you see the CPT row but you can’t edit?
Because I have various CPT, and with a CPT that I create automatically, I see de results but I can’t edit, but with a CPT that I create manually, I can edit the result. What I’m doing wrong?
Hi,
not working. 🙁
Scenario:
I have 2 users (user1,user2), Rol Author.
The user1 has created a CPT restaurant called rest1, and when I log into a Backend with user2 I can edit rest1. :S
I’ve tried all the combinations:
add_action( 'pre_get_posts', 'filtre');
function filtre($query) {
//tried option 0
//global $user_ID;
//tried option 1
//global $current_user;
if( !is_admin() ) {
$query->set('author', get_current_user_id());
//tried option 0
//$query->set('author', $user_ID);
//tried option 1
//$query->set('author',$current_user->id);
//tried option 2
//$user = wp_get_current_user();
//$query->set('author_name', $user->data->user_nicename );
}
return $query;
}
I don’t know whatelse.
Help please!
Thanks!
Ignore my previous question, I can confirm that Date and Time Picker field works fine in ACF v4.1.4
Thank you dominic 🙂
I’ve gotten around this with an admin stylesheet in my theme that has a pretty messy mix of floats/clears/borders, along with some JS to match the heights of divs that are floated next to each other. It’s super ugly (on the code side), and hard to maintain when I add/remove/move fields, particularly when conditional logic is involved. Not quite sure what a good interface for it would look like, though.
<a href="<?php the_field('look_1_shop_now_link'); ?>" target="_blank">SHOP NOW</a>
Hi there @Hube2,
I too have required this functionality today, due to being at work I am unable to test this for a variety of taxonomies although I have used it for shopp-categories.
Please let me know how you get on with this.
https://github.com/WazzaJB/ACF-Taxonomy-Depth-Rule
Wazza

Hi @Wally
Your code suggests that the previous developer has a custom function to register custom fields. That or their are using another plugin to ACF as some of the parameters are missing / different.
I think some debugging is required from your end to see how the fields are registered with ACF

Hi @AmandaB
Thanks for the request. Your right, this would be a great feature and I’ll add it to the to-do
Cheers
Elliot

Hi @roger
My first question is to ask where the user is editing the post.
If the users are logging into the WP backend and editing posts via the normal wp-admin interface, then you could create a custom location rule!
A custom location rule will allow you to look at the current logged in user and compare it to the post’s author. If they match, return true, if not, return false.
This will show / hide the field group on a user basis!
You can read how to create custom location rules here:
http://www.advancedcustomfields.com/resources/tutorials/custom-location-rules/

Hi @ashkas
Thanks for the reply. I’m not sure why this would be causing any issues with ACF. It doesn’t seem to change any core functionality at all…
Is it possible that there is a Syntax error which is breaking the admin_enqueue_scripts action?

Aha, well in that case you were totally on the right path!
Filtering by “author” takes a user ID, while filtering by “author_name” will take a text string. Try this:
add_action( 'pre_get_posts', 'filtre');
function filtre($query) {
if( !is_admin() ) {
$query->set('author', get_current_user_id() );
}
return $query;
}
Or alternatively, you could get the string name first and filter by “author_name” instead:
$user = wp_get_current_user();
$query->set('author_name', $user->data->user_nicename );
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.