Hello,
This is now an old thread but it is just what I need – that is if I can get it to work.
My problem is that I just cant get the links in the list to trigger the infowindow popup.
Any chance you can provide a few more details on how to get this to work?
For example, you mentioned that you “… In the list items I add the latitude to the LI itself”
What do you mean by that?
Thanks
Maybe there’s an error in the code above, but it looks ok to me.
Anyone?
Hi James,
I have a similar issue, but I’m a bit unsure how to implement the fix.
The first map works fine and shows locations.
The google map in the form to submit new locations, however, does not work –
I have tried removing the script – that removes the top google map but the map in the submission form still doesnot show.
Any ideas?
Thanks for your help
Patrick
Thanks John,
I made the changes you suggested.
Not sure if the changes were just recommendations, or for getting the feature image set the first time around.
In any case, nothing really has changed.
Is there a way to get the feature image set the first time around?
Can I writer another function or something to force the trigger?
Thanks
Patrick
I couldn’t find a publish_date – just post_date and post_date_gmt
Better pic
OK – so it seems that the post_date is being set to current, but post_date_gmt is not being set at all – please see attached
OK – with the below code $post_id is echoed as ‘8’ – which is NOT the id number of the draft post (when i look at the link in admin), and $acfDate echoes nothing, I guess because the correct post id is not being obtained
function my_acf_save_post( $post_id ) {
global $post;
$post_id = $post->ID;
$acfDate = get_field('field_5a4cd9975f9a7', $post_id);
//Test if you receive the data field correctly:
echo $post_id;
echo $acfDate;
exit (-1);
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_date'] = $acfDate;
wp_update_post( $my_post );
}
add_action('acf/save_post', 'my_acf_save_post', 20);
Easy if you know how! I tried vie myphp but couldn’t see saved publish date as a field.
My feeling is that $acfDate is not being populated – can I echo for test?
Ah, of course that date will not be copied over to the posts’s publish date because I’ve just taken out that piece of code and replaced it with the error checking code – sorry
Thanks again. Done that
function my_acf_save_post( $post_id ) {
global $wp_query;
$post_id = $wp_query->get_queried_object_id();
$acfDate = get_field('post_date', $post_id);
//Test if you receive the data field correctly:
//echo $acfDate;
//exit (-1);
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_date'] = $acfDate;
$post = wp_update_post( $my_post );
if (is_wp_error($post)) {
echo 'WP ERROR: <pre>'; print_r($wp_error); echo '</pre>'; die;
}
}
add_action('acf/save_post', 'my_acf_save_post', 20);
But there seems to be no change in the behaviour of the acf-form – the post is still saved as draft – the custom date field is completed but the post’s publish details still say ‘Publish Immediately’ with today’s date…
OK – the return format for the date field is definitely correct – ‘Y-m-d H:i:s’
I have tried changing post_date to field_5a4cd9975f9a7 – no luck.
Post Publish details still show ‘Immediately’ with current date/time.
Maybe the error checking code will help me, but I am still struggling a bit to understand where to place it – should I place it in my frontend page with acf_form – if so where in the page should it go?
Or should it be placed in the functions.php – if so where?
Thanks for your help
P
I have an acf form page with the following code
<?php
/*
Template Name: Featured
*/
acf_form_head();
get_header();?>
<div id="container" class="row">
<div id="primary" class="small-12 columns">
<?php
acf_form(array(
'post_id' => 'new_post',
'field_groups' => array(54), // Used ID of the field groups here.
'post_title' => true, // This will show the title filed
'post_content' => true, // This will show the content field
'form' => true,
'new_post' => array(
'post_status' => 'draft' // You may use other post statuses like draft, private etc.
),
'return' => '%post_url%',
'submit_value' => 'Review',
));
?>
</div><!-- #primary -->
</div> <!-- #container -->
<?php get_footer(); ?>
This takes the user to a review page where the they can edit further if they wish.
Can I then update the publication date within the code above?
Also, the code for error testing – where would I put that?
Thanks
Patrick
Hi John
Thanks for your reply.
There were two posts I found on acf about setting publication post date using acf date/time picker on the fontend. Another post I’ve found on stackexchange.
https://support.advancedcustomfields.com/forums/topic/set-post-publish-date-by-custom-field/
In any case – I have an acf form on the front end where the user creates a draft post. The form works fine and creates the draft post as required. However, I’d like to be able to include a date/time picker and have the selected date/time set as the post’s publication date. I tried using the following code but had no luck
function my_acf_save_post( $post_id ) {
$acfDate = get_field('post_date', $post_id);
//Test if you receive the data field correctly:
//echo $acfDate;
//exit (-1);
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_date'] = $acfDate;
wp_update_post( $my_post );
}
add_action('acf/save_post', 'my_acf_save_post', 20);
Any ideas?
Thanks
P
OK – this looks like what I’m looking for – I have an acf form with field (date-time) date/time picker that I would like to use to set the publication date of the draft post
The acf form works fine in my wp template – I just need the date/time picker to set the publication date…?
Could you please highlight what I need to do with the above to get the basics working?
I have tried putting this code into my functions.php without any luck…
function my_acf_save_post( $post_id ) {
if(!is_admin()){
// get new value
$theDate = get_field('post-date', $post_id, false);
if($theDate){
$theDate = date_create_from_format('Ymd', $theDate);
$theDate = date_format($theDate, 'Y-m-d H:i:s');
$my_post = array(
'ID' => $post_id,
'post_date' => $theDate,
);
// do something
// unhook this function so it doesn't loop infinitely
remove_action('acf/save_post', 'my_acf_save_post');
// update the post, which calls save_post again
wp_update_post( $my_post );
// re-hook this function
add_action('acf/save_post', 'my_acf_save_post');
}
}
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
Hi,
I’m having a problem implementing this code and could do with a hand.
I have an ACF date/time selector field ‘post_date’ that I want to create publication date in new post
I have set date/time format to Y-m-d H:i:s
And I have put the following code into my functions.php
function my_acf_save_post( $post_id ) {
$acfDate = get_field('post_date', $post_id);
//Test if you receive the data field correctly:
//echo $acfDate;
//exit (-1);
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_date'] = $acfDate;
wp_update_post( $my_post );
}
add_action('acf/save_post', 'my_acf_save_post', 20);
I have not set $post_id – is this the reason it is not working do you think? If so, how do i set post_id?
Thanks for your help
Thanks…Looks like this might be the way to go. The only reason I didn’t want to do this was that I’ll end up having a separate category for each holiday, and also I wanted the Holiday code to be ‘required’ – not sure if I can do this with categories.
Good for SEO is a definite plus though!
Cheers
p
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.