I’m sure for people here this will be a no-brainer, but I’m new to ACF and not a coder, but I do have a basic knowledge of WordPress and how it works.
I have set up a custom post type called ‘events’ and a custom field called ‘event_date’.
I’m using Oxygen and trying to set up a repeater to query the post type ‘events’, but how do I get it to only show events on a specific day?
Any help appreciated.
I found this topic from 2019 which was solved. But was trying to make this work with sub fields. i.e. – What if the Events fields were repeater fields that could be populated multiple Places fields (Map/Address fields, etc.). I gave it a shot below, but I’m missing something.
add_action('acf/save_post', 'save_event_update_address', 20);
function save_event_update_address($post_id) {
if (get_post_type($post_id) != 'events') {
// not and event post, bail
return;
}
// get location post ID
// you said it's a relationship field, a relationship field will turn an array of posts
// I am setting the 3rd parameter because we only need the IDs
$related_places = get_sub_field('relationship_field_name');
// also the
if ($related_places) {
$place_id = $related_places[0];
$address = get_field('address_field_on_place_name', $place_id);
update_sub_field('address_field_on_event_repeater_name, $address, $post_id);
}
}
I use a repeater field for creating a visitor list:
First Name Last Name
---------------------------
1 John Miller
---------------------------
2 Tom Brown
---------------------------
3 Mike Smith
---------------------------
...
My field can be populated in two ways:
My problem:
So, my question is:
How can I prevent this? How can I check if new entries were added to the list before it is saved? I guess, I could use the acf/update_value filter or the acf/save_post action – but I don’t know how.
Thanks a lot,
Karl
We have a PHP snippet that is being deployed using the Woody Snippets plugin. The code works great and does what it needs to do, which is to populate an ACF text field when the ACF form is saved or updated on the backend.
But, that snippet is set to “run everywhere” because the only other option within Woody Snippets is to add it to a post or page via a shortcode. We don’t know how to add a shortcode (and have it execute) on an ACF/custom post type form on the back-end.
The question: How could we edit the snippet (below) to only execute when someone is editing our custom post type on the back-end? We need this because running the snippet everywhere is breaking the Elementor editor, so we’re unable to edit the custom post template.
Hope that makes sense! Here’s our snippet, if it matters:
// This populates and saves search terms for product landing pages based on what lives in the product tables
function save_search_terms( $post_id ) {
$searchterms = array();
if( have_rows('product_table') ):
while( have_rows('product_table') ) : the_row();
// Loop over sub repeater rows
if( have_rows('product_table_products') ):
while( have_rows('product_table_products') ) : the_row();
// Get sub value
foreach( $tempsearchterms as $tempsearchterm );
$tempsearchterm = get_sub_field('product_table_product');
$searchterms[] = $tempsearchterm->part_number . " " . $tempsearchterm->product_name . " " . $tempsearchterm->model_type;
endwhile;
endif;
endwhile;
endif;
// update field
update_field('search_terms', implode(' ', $searchterms) );
}
add_action('acf/save_post', 'save_search_terms');
?>
<style type="text/css">
#search-terms {
pointer-events: none;
}
</style>
Hi
I have registered an ACF field as a Gutenberg-Block.
add_action('acf/init', 'my_acf_init');
function my_acf_init() {
if( function_exists('acf_register_block_type') ) {
acf_register_block_type(array(
'name' => 'event-date',
'title' => __('Veranstaltungs-Datum'),
'description' => __('Veranstaltungs-Datum'),
'render_template' => 'block-rendering/events_date.php',
'icon' => 'format-image',
'keywords' => array( 'Event' ),
'mode' => 'edit',
'supports' => array('multiple' => false, 'className' => true ),
'post_types' => array('events',),
));
}
}
It is a repeater field with a date picker (and other fields).
Is there a way to automatically transfer the date from the Gutenberg block to another ACF field (not registered as a block)?
Thank you all!
Matthias
Hello ,
In the site that i develop i was try to change a class to a div by the date that choose in the date field in the admin, the page is events page, and i am using with a repeater field, the date field is a sub-field.
What in the end i want to achieve – When the date is far from the date event or it is the day – add class to a div “webinar-holder”.
When the date of the event has passed – add class “old-event”
i was try as follow
<?php if( $webinarDate <= date('dmY') ) { ?>
<div class="webinar-holder old-event">
<?php } elseif ( $webinarDate >= date('dmY') ) { ?>
<div class="webinar-holder">
<?php } ?>
And this is the long code (with the repeater):
<div class="webinars-container">
<?php if( have_rows('webinars-repeater') ){ ?>
<?php while( have_rows('webinars-repeater') ) { the_row();
// vars
$webinarTitle = get_sub_field('webinar-title');
$webinarDate = get_sub_field('webinar-date');
$webinarStartTime = get_sub_field('webinar-time-start');
$webinarEndTime = get_sub_field('webinar-time-end');
$webinarLecturerImg = get_sub_field('webinar-lecturer');
$webinarAboutLecturer = get_sub_field('webinar-about-lecturer');
$webinarLink = get_sub_field('webinar-link');
$webinarLinkText = get_sub_field('webinar-link-text');
?>
<?php if( $webinarDate <= date('dmY') ) { ?>
<div class="webinar-holder old-event">
<?php } elseif ( $webinarDate >= date('dmY') ) { ?>
<div class="webinar-holder">
<?php } ?>
<!-- details -->
<div class="webinar-details">
<div class="webinar-subject">
<?php if (get_locale() == 'he_IL') { ?>
<div class="title">על מה נדבר?</div>
<?php } elseif (get_locale() == 'en_US') { ?>
<div class="title">What will we talk about?</div>
<?php } ?>
<?php echo $webinarTitle; ?>
</div>
<div class="webinar-date">
<?php if (get_locale() == 'he_IL') { ?>
<div class="title">בתאריך</div>
<?php } elseif (get_locale() == 'en_US') { ?>
<div class="title">Date</div>
<?php } ?>
<?php echo $webinarDate; ?>
</div>
<div class="webinar-time">
<?php if (get_locale() == 'he_IL') { ?>
<div class="title">בין השעות</div>
<?php } elseif (get_locale() == 'en_US') { ?>
<div class="title">Time</div>
<?php } ?>
<?php echo $webinarStartTime; ?> - <?php echo $webinarEndTime; ?>
</div>
</div>
<!-- end details -->
<div class="webinar-about-lecturer-container">
<div class="lecturer-image">
<img src="<?php echo $webinarLecturerImg['url']; ?>" alt="<?php echo $webinarLecturerImg['alt'] ?>" />
</div>
<div class="about-lecturer-text"><?php echo $webinarAboutLecturer; ?></div>
<a href="<?php echo $webinarLink; ?>" target="_blank" class="webinar-link" rel="nofollow"><?php echo $webinarLinkText; ?></a>
</div>
</div>
<?php } ?>
<?php } ?>
</div>
I don’t now what i missed that isn’t working.
I will very appreciat for every Instruction what to do to fix this….
Hi,
So i have a repeater inside post-type ‘properties’ that stores Lot No and Auction Date for all the Auctions a property is in.
When going into an event page, say for 12th August it needs to list all of the properties in this auction in Lot No order.
When i use WP Query i’m doing it as so:
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'auctions_$", "meta_key LIKE 'auctions_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
$args = array (
'post_type'=>'properties',
'post_status'=>'publish',
'posts_per_page'=> 40,
'paged'=> $paged,
'suppress_filters' => false,
'meta_query' => array(
'proparray' => array(
'key' => 'auctions_$_auction_date',
'value' => $today2,
'compare' => 'LIKE',
),
'lot-nos' => array(
'key' => 'auctions_$_lot_no',
'type' => 'NUMERIC',
),
),
'orderby' => array(
// 'auction-dates' => 'ASC',
'lot-nos' => 'ASC',
),
);
$wpb_all_query = new WP_Query($args);
My problem is that it’s picking up Lot Nos from other rows. So if a property has the following date:
Auction Date : 7th June 2020
Lot No: 2
Auction Date: 12th August 2020
Lot No: 14
It is picking up the auction date 12th August 2020, but ordering it as Lot No 2, NOT 14. I need it to match to the specific row of the date in question, then get the Lot No from that row. is this possible?
Hi all.
I’m building a website that is for booking events, the e-commerce platform is woocommerce. I’ve acted an action to add a new page to the user account called family, where I want the user to be able to manage their family members and contact info.
So far I’ve added the page, created a repeater for user where they can add a family member and fill in that members information, it saves and all works great.
Now I’d like to add an ACF group before the repeater that has main information such as emergency contact details and next of kin, but I can’t figure out how to display two fields (the group and the repeater) within the one action and only have one save button to save the details to the users account.
This is what I have so far that works for the repeater, but if anyone could steer me in the right direction as to how to add the group field, it’d be hugely appreciated.
<?php
acf_form_head();
get_header();
?>
Family
<div class="family-members-form"><?php
if ( !is_user_logged_in() ){
echo 'You are not logged in. <br /> <a href="' . get_permalink(31) .'">Log In →</a>';
} else {
$user = wp_get_current_user();
$options = array(
// 'field_groups' => ['group_5cbd99ef0f584'],
'fields' => ['field_5f24194f719ca'],
'form_attributes' => array(
'method' => 'POST',
'action' => admin_url("admin-post.php"),
),
'html_before_fields' => sprintf(
'<input type="hidden" name="action" value="adaptiveweb_save_profile_form">
<input type="hidden" name="user_id" value="user_%s">',
$user->ID
),
'post_id' => "user_{$user->ID}",
'form' => true,
'html_submit_button' => '<button type="submit" class="acf-button button button-primary button-large" value="Update Profile">Update Profile</button>',
);
acf_form($options);
}
?>
</div>
I’m struggling with this. I a have list of date (not fixed, I can have as many date as I want) made thanks to the ACF Repeater. In my query, I want to filter by date.
But, I have to hide some post if the date choosen is not between my 2 date fields (evenement_date_start and evenement_date_end). This is an example of my date list.

So if I choose between 01/10/2020 and 20/10/2020, the event should not show up. But right now, it does and I can’t figure out why.
This is my query args, my date and variable have this format “Ymd” :
$args[] =
['relation' => 'OR',
['relation' => 'AND',
[
"key" => "evenements_liste_dates_AAA_evenement_date_start",
"compare" => "<=",
"type" => 'DATE',
"value" => $startDate,
],
[
"key" => "evenements_liste_dates_AAA_evenement_date_end",
"compare" => ">=",
"type" => 'DATE',
"value" => $endDate,
]
],
['relation' => 'OR',
[
"key" => "evenements_liste_dates_AAA_evenement_date_start",
"compare" => "BETWEEN",
"type" => 'DATE',
"value" => [$startDate, $endDate],
],
[
"key" => "evenements_liste_dates_AAA_evenement_date_end",
"compare" => "BETWEEN",
"type" => 'DATE',
"value" => [$startDate, $endDate],
]
],
];
And my post where rewriting
add_filter('posts_where', function ($query, WP_Query $wp_query) {
if(!is_admin() && $wp_query->query_vars['post_type'] == "evenement" && !$wp_query->is_main_query()) {
$query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_start'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_start'", $query);
$query = str_replace("meta_key = 'evenements_liste_dates_AAA_evenement_date_end'", "meta_key LIKE 'evenements_liste_dates_%_evenement_date_end'", $query);
}
return $query;
}, 10, 2);