I put this code in my functions file:
add_action('acf/save_post', 'test_update_post_date_from_acf', 20);
function test_update_post_date_from_acf($post_id) {
// remove this filter to prevent potential infinite loop
remove_filter('acf/save_post', 'test_update_post_date_from_acf', 20);
// date format must be "Y-m-d H:i:s"
$post_date = get_field('email_scheduled_date');
$post = wp_update_post(array(
'ID' => $post_id,
'post_date' => $post_date));
}
And I made sure that my datepicker return format is set to: Y-m-d H:i:s
I know this is an old post but I am trying to publish a front-end post with a future date using a date picker field and nothing I am finding is working.
Perhaps there is a newer way to get this done here nearing 2023?
I cannot manage to get this working whatsoever…. hopefully someone can assist. Perhaps things have changed in the last 8 years and there is a better way to do this?
Here’s my code to display my form:
<?php acf_form(array(
'post_id' => 'new_post',
'id' => 'new-email',
'new_post' => array(
'post_type' => 'emails',
'post_status' => 'future',
'field_groups' => array(1091),
'post_title' => true
),
'return' => '',
'submit_value' => 'Add new email'
)); ?>
Not sure if I have the field_groups ID correct or not. Not sure how to retrieve that. Is that the “post id” of the field group?
Here’s my functions file code:
add_filter('acf/pre_save_post' , 'emails_pre_save_post', 10, 1 );
function emails_pre_save_post($post_id) {
// check if this is to be a new post
if ($post_id != 'new_emails') {
return $post_id;
}
// The date picker field
// change field_563657f49b4d9 to the field key of your date field
$postdate = date('Y-m-d H:i:s', strtotime($_POST['acf']['field_emails_email_scheduled_date']));
// Create a new post
$post = array(
'post_type' => 'emails',
'post_title' => $_POST['acf']['_post_title'],
'post_status' => 'future',
'post_date' => $postdate,
'edit_date' => true
);
// insert the post
$post_id = wp_insert_post( $post );
// return the new ID
return $post_id;
}
Thank you for the response.
Do you have links to previous discussions that could help me further? I can’t find anything that would help fit for my case and it only makes sense that someone else has needed to something similar.
Forgive the bump!
Still struggling with this one and any help would be awesome!
Update:
The above answer will allow you to update previously established posts but not work for new posts, so the following function addresses that and allows for new posts and previous posts to modify the title from acf fields:
function update_contacts_title($post_id) {
if( have_rows('contact_info') ):
while( have_rows('contact_info') ): the_row();
$first_name = get_sub_field('first_name', $post_id);
$last_name = get_sub_field('last_name', $post_id);
$title = $first_name . '-' . $last_name;
$slug = sanitize_title( $title );
endwhile;
endif;
$postdata = array(
'ID' => $post_id,
'post_title' => $title,
'post_type' => 'contacts',
'post_name' => $slug
);
wp_update_post( $postdata );
}
add_filter('acf/save_post', 'update_contacts_title', 10, 3);
Here’s the answer:
function update_contacts_title($value, $post_id, $field) {
if( have_rows('contact_info') ):
while( have_rows('contact_info') ): the_row();
$first_name = get_sub_field('first_name', $post_id);
$last_name = get_sub_field('last_name', $post_id);
$title = $first_name . '-' . $last_name;
$slug = sanitize_title( $title );
endwhile;
endif;
$postdata = array(
'ID' => $post_id,
'post_title' => $title,
'post_type' => 'contacts',
'post_name' => $slug
);
wp_update_post( $postdata );
return $value;
}
add_filter('acf/update_value/name=last_name', 'update_contacts_title', 10, 3);
Well, one of my issues is that the first_name
and last_name
fields are within a group! I forgot about that but I’m still having trouble building the function to work as a group.
Any help would be appreciated!
I’ve included some images to help explain this better.
The first image is simply outputting the data on the front end.
The second image shows the acf admin fields.
Basically, the Grades (5.5, 6, 6.5) would be included in the first dropdown and depending on which one is selected, it would show the size fields in the next dropdown.
A little bumpity bump bump!
Just gonna bump this topic up here.
There must be a solution this somewhere but I can’t see to find one over the last couple of weeks.
I don’t normally solve things this quickly but I was able to use a php counter to achieve my results. The only issue I have left are the UiKit previous and next arrows not highlighting the thumbnail for the image that is being displayed. The only way I can highlight the thumbnail is by clicking the thumbnails themselves. Here’s my final code for anyone in the future. If something could be done differently to make this less complicated, I’m open to suggestions.
<div class="uk-container">
@if( have_rows('gallery') ) @php $i = 0; @endphp
<div class="gallery uk-child-width-1-5@s uk-grid-match uk-text-center" uk-grid>
@while ( have_rows('gallery') ) @php $i++; @endphp
<a href="#modal-media-image-{{ $i }}" uk-toggle>
<div class="uk-card uk-card-hover uk-card-body" id="{{ $i }}">
@php the_row();
$images = get_sub_field('gallery');
$image = $images[0]
@endphp
@if( $image )
<h3>@php the_sub_field('gallery_title') @endphp</h3>
<img src="{{ $image['sizes']['thumbnail'] }}" alt="{{ $image['alt'] }}>" />
<h5>@php the_sub_field('gallery_sub_title') @endphp</h5>
@endif
</div>
</a>
<div id="modal-media-image-{{ $i }}" class="uk-flex-top" uk-modal>
<div class="uk-modal-dialog uk-width-1-2 uk-margin-auto-vertical">
<button class="uk-modal-close-outside" type="button" uk-close></button>
<div class="uk-position-relative" uk-slideshow="animation: fade">
@php $allimages = get_sub_field('gallery') @endphp
@if( $allimages ) @php $i = 0 @endphp
<ul class="uk-slideshow-items">
@foreach( $allimages as $image ) @php $i++ @endphp
<li>
<img src="{{ $image['sizes']['large'] }}" alt="{{ $image['alt'] }}" uk-cover>
<a class="full-size" href="{{ $image['url'] }}">Full size</a>
</li>
@endforeach
</ul>
<div class="uk-position-bottom-center uk-position-small">
<ul class="uk-thumbnav">
@foreach( $allimages as $image ) @php $i++ @endphp
<li uk-slideshow-item="{{ $i }}">
<a href="#">
<img src="{{ $image['sizes']['thumbnail'] }}" width="50" />
</a>
</li>
@endforeach
</ul>
</div>
<a class="uk-position-center-left uk-position-small uk-hidden-hover" href="#" uk-slidenav-previous uk-slideshow-item="previous"></a>
<a class="uk-position-center-right uk-position-small uk-hidden-hover" href="#" uk-slidenav-next uk-slideshow-item="next"></a>
@endif
</div>
</div>
</div>
@endwhile
</div>
@else
@endif
</div>
The AJAX request appears to be timing out. We have over 500 products in WooCommerce and only 17 posts for a custom post type.
Is there any easy way to exclude WooCommerce products from the posts in ACF?
Hi, thank you for the response.
/listings is an archive template I created which successfully displays my loop of properties, the sidebar and the header image (which is displayed if the archive page is /listings)
Once I add the filter to the URL, it filters the properties correctly but I lose the header image and the sidebar.
Yesterday I created a widget to display properties that are for sale and lease. Then I realized the sidebar shows up but only displays this new widget and only displays properties for the given filter (for sale or for lease).
Does that help make more sense?
Thanks again.
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.