Hello, So I have added the following code to my function.php but for some reason iam not getting any validation and the page is just saved no matter what. Any ideas?
function my_acf_validate_save_post()
{
$start = $_POST['field']['field_591a5d2s941df'];
$start = new DateTime($start);
$end = $_POST['field']['field_539a5a2s921d7a'];
$end = new DateTime($end);
// check custom $_POST data
if ($start > $end) {
acf_add_validation_error('late_avail_date_end', 'End Date should be greater than or Equal to Start Date');
}
}
add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);
So ive managed to get it working using the following. Any suggestions?
function set_event_month($post_id, $post, $update) {
$event_date = get_field('event_date_start', $post_id, FALSE ,FALSE); // Event Start Date
$event_date = new DateTime($event_date);
$event_date = $event_date->format('F Y'); // Format date to month and year
update_field('event_month_year', $event_date); // Update field
}
add_action('save_post', 'set_event_month', 10, 3);
Hello,
Ive tried that but have been unable to show the results nothing appears for the title
$date = get_posts(array(
'post_type' => 'course-dates',
'meta_query' => array(
array(
'key' => 'course', // name of custom field
'value' => '"' . $course_id . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $date ): ?>
<table>
<thead>
<tr>
<th class="content-pad">Date</th>
<th>Time</th>
<th>Spaces</th>
<th>Price</th>
<th>Book</th>
</tr>
</thead>
<tbody>
<?php foreach( $date as $dates ):
$spacesleft = get_field('spaces',$dates->ID);?>
<tr>
<td class="content-pad"><?php the_field('startdate',$dates->ID);?>
<?php $course_title = get_field('course');
?>
<?php if( $course_title ): ?>
<?php foreach( $course_title as $course ): ?>
<?php echo get_the_title( $course->ID ); ?>
<?php endforeach; ?>
<?php endif; ?>
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.