
Np 🙂
for future reference, get_permalink() can take one parameter which is a post id while the_permalink does not.. that is why it didnt work.

ah well..
If we look at the code logically.. you input the $_POST into the $fields variable.. then change the value of one of the array keys in $fields, but $_POST is never really altered.. $fields != $_POST if you see what I mean 🙂
So your code works in a sense but it is not affecting the actual values being saved.
I think this should work:
function my_acf_save_post( $post_id )
{
// vars
$fields = false;
// load from post
if( isset($_POST['fields']) )
{
$fields = $_POST['fields'];
// concert details
// event start date
//$fields['field_5217ac66687dc']
// event end date
//$fields['field_524b4ca5ff418']
if( empty( $fields['field_524b4ca5ff418'] ) )
$_POST['fields']['field_524b4ca5ff418'] = $fields['field_5217ac66687dc'];
// calendar details
// event start date
//$fields['field_524b4c06af2a2']
// event end date
//$fields['field_524b4c3aaf2a4']
if( empty( $fields['field_524b4c3aaf2a4'] ) )
$_POST['fields']['field_524b4c3aaf2a4'] = $fields['field_524b4c06af2a2'];
}
// ...
}
// run before ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'my_acf_save_post', 1);
I suppose you could clean that up a bit if you like and I’m not 100% sure if I wrote the $_POST[‘field’][‘fieldkey’] correctly since I havent looked at the arrays myself but all in all it should set you on the right path!

are you sure the fields are even set?
You could do some debugging:
print_r($fields);
die();
put that after you set the $fields variable. when you update a post it should then just send you to a white page within the admin with the $fields variable printed.

lol sorry, I wrote get_permalink in the text and the_permalink in the code..
it should be
echo get_permalink($postid);

Np Kyle,
you wont have to worry about the field keys tho, they’re actually the ones you really should use since they will never change and are 100% unique compared to field names which depends on the developers paranoia 😉 (I myself always write custom fields like “acf_reference_name” since I want to be 500% sure it would never collide).

Great,
Yes since you do not output the repeater as posts get_permalink() retrieves the current pages link. in order to change this you can do:
the_permalink($postid);
then it’ll fetch either current page or parent page (if there is one). Just like the_field and get_field.

Hi!
I believe the field_524b4c06af2a2 is the field key for one of your fields. you can open up the panel settings when on the edit page of the field group and check to show field keys and you’ll see which ones you should work with.

Hi @sasori390,
I think this should just about do it.. this can be used outside of the loop which I assume you are doing. If not you could probably remove the global $post.
<?php
global $post;
if($post->post_parent){
$postid = $post->post_parent;
}else{
$postid = $post->ID;
}
?>
<?php if(get_field('content-container', $postid)): ?>
<ul>
<?php while(has_sub_field('content-container', $postid)): ?>
<li><a href="<?php the_permalink() ?>#<?php the_sub_field('anchor'); ?>"><?php the_sub_field('header'); ?></a></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>

My bad, its called message field 🙂

A headache, sure! possible, yeah!
don’t add a textfield, add a html-field and put the a tag in the description… it’ll appear on the edit page as an anchor. 🙂
to put your own script into the edit page you can use the admin_head hook
http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head

great 🙂 No need to feel embarrassed!
You could simply target the appropriate input fields and alter their value when user clicks on the image.. when the user first click the link, save the link object to a variable and pass that along to the function for the coordinates. then inside the function where user has clicked the image and gotten the coords you use the link-object to target the corresponding x and y inputs. The code below is just an example of how you could input the values in the right fields 🙂
$('.open-imglatlon').click(function(e){
e.preventDefault(); //this prevents regular link-click.
var linkobject = $(this);
openpopup(linkobject); //the function for opening the popup blabla
});
function openpopup(linkobject){
//blablabla all the code to retrieve the image, put it in the popup and do the x-y coord script
var xcoords = '3213213213'; //just for show,
var ycoords = '3213213213'; //just for show,
// Use the linkbutton, go to the parent tr, find the parent trs siblings which are also tr, then inside those find the input with a parent element with the specific class and change the value of the input to x or y. You can find the specific class from looking in the code on your admin page with a repeater row created.
linkobject.closest('tr').siblings('tr').find('.field_key-field_4f9e754fdedc2 input').val(xcoords);
linkobject.closest('tr').siblings('tr').find('.field_key-field_4fwdwaddfffew input').val(ycoords);
// I think this could work altho its possible that since the siblings are more than one it wont work.. then you'll have to just get the tr siblings and loop through each like so:
linkobject.closest('tr').siblings('tr').each(function(){
$(this).find('.field_key-field_4f9e754fdedc2 input').val(xcoords);
$(this).find('.field_key-field_4fwdwaddfffew input').val(ycoords);
});
}

with “a-tag” im just referring to a regular anchor.
You could put a hmtl field at the end of the repeater-row with:
<a href="#" class="open-imglatlon">Set image coordinates</a>
and then in your javascript you trigger the popup when user clicks open-imglatlon
$('.open-imglatlon').click(function(e){
e.preventDefault(); //this prevents regular link-click.
});

Hi Christopher.
What exactly are you trying to achieve?
You cant query an acf field like you query wp_query since it’s just plain data in an array/string/object.

Hi Ashby!
Have you looked at the gallery field addon?
http://www.advancedcustomfields.com/add-ons/gallery-field/
It’ll let you upload as many images as you want and they’re immediately added to the field. Then your client can simply drag and drop them in order 🙂

I’d say it very much depends on how advanced you want the function to be.. and user friendly.
I think the way you imagine it could work.. but to make it easier for you you could add a html-field at the end of the repeater row with an a -tag which you hook up your custom script to.. that way you wont have to hack anything into the repeater.
You’ll have to do some custom javascript obviously.. do this by adding a filter to admin_head:
http://stackoverflow.com/questions/3326967/how-to-add-custom-javascript-to-wordpress-admin
With the script I suppose you’ll just have to be able to integrate that script you’ve linked.. then have it output the coordinates into the appropriate fields..
I don’t think you’ll have to publish the post with the image before using the script/popup. You’ll retrieve the image when the user actually click the “add coordinates” popup-link anyway so as long as there’s an image there in the code your fine.
I have to say this is a deucy and it’d be interesting to make it into a plugin.. I haven’t had use for a function like this myself but I’ve seen this being used on occasion.

Hi @elliot
Hah.. what do you know! That is indeed wierd..

Hi Pey,
You can pay with credit cart via Paypal.. just continue with the payment and when coming to the paypal window there’s a link below the login-section.

@elliot wouldn’t that be redundant since we’re already passing along the current page/post id?

Great 🙂
Glad to help out!

that does not matter with the code i provided.. what it’ll do is loop through all repeaters and fetch the ssm_featured_page dropdowns value. But I guess that is an array then so you’ll do this (if you want it foolproof for multiple selects:
<?php while (has_sub_field('ssm_featured_content')) { ?>
$postObjects = get_sub_field('ssm_featured_page');
if($postObjects){
foreach($postObjects as $post){
setup_postdata($post);
the_title();
}
wp_reset_postdata();
}
<?php echo $postObject->$post_title; ?>
<?php } ?>

what is ssm_featured_content? your repeaterfield?
you’ll need to change it to:
<?php while (has_sub_field('ssm_featured_content')) { ?>
<?php $postObject = get_sub_field('ssm_featured_page'); ?>
<?php echo $postObject->$post_title; ?>
<?php } ?>

Haha been there!
Good thing it worked out 🙂
/Jonathan

I think you’ll have to pass along the current posts id as well (or use global $post)..
<?php
function example($field, $postID) {
$post_object = get_field($field, $postID);
if($post_object) {
# get post data
$post = $post_object;
setup_postdata($post);
?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php
# reset postdata
wp_reset_postdata();
}
}
example('my_post_object', $post->ID); //in your template, assuming you do this inside the loop. If outside try replacing $post->ID with get_the_ID()
?>

I’ve worked with ACF and WPML quite a bit myself and we’ve developed the habit that if you want to create a translation with the content copied you’d have to go into the post/page and then duplicate it, head over to the new post/page and hit the translate separately button.
I’m not surprised why WPML blame ACF. Honestly my experience with their support is pretty lousy (and I’m not the average joe who run a hobby-site). I’m not saying the issue isn’t with ACF but to my knowledge ACF uses standard post_meta values which WPML should be able to copy when making a new translation.. I’ve made a copy-function of my own involving ACF meta fields without issues (not related to WPML) so…

Hi!
You can create a field of any kind.. since you want a dropdown select that one and insert your values. Then in location rules you can first add it to posts and then add a second location rule set to users.. make sure the locationrules are set to any and not all.
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.