Thanks, @airesvsg, I got everything working.
@airesvsg What about editing repeater fields? I’m not sure how to target a repeater field.
@arjen_m Are you using a field named “start_date” in ACF? For my code, the argument looks in that field to see if the date falls between today’s date and 12 months from now. If it is not called “start_date” you will need to change the following to whatever your field is called.
‘meta_key’ => ‘start_date’,
Hi eike,
You need to set up args that filter the date. I actually have this set and running on my site.
I set the timezone to my timezone and then set 2 variables, one is set to todays date and the other is set to a year from now.
<?php
//Set server timezone to central
date_default_timezone_set('America/Chicago');
//Today's date
$date_1 = date('Ymd', strtotime("now"));
//Future date - the arg will look between today's date and this future date to see if the post fall within the 2 dates.
$date_2 = date('Ymd', strtotime("+12 months"));
?>
Then I set a variable to determine if the post is in the future:
//arg to determine if the post is an upcoming event.
$upcoming_args = array(
'post_type' => 'event',
'posts_per_page' => -1,
'meta_key' => 'start_date',
'meta_compare' => 'BETWEEN',
'meta_type' => 'numeric',
'meta_value' => array($date_1, $date_2),
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
?>
Set up a new upcoming event query:
<?php
// the upcoming events query
$upcoming_query = new WP_Query( $upcoming_args );
?>
Then the loop:
<?php if ( $upcoming_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $upcoming_query->have_posts() ) : $upcoming_query->the_post(); ?>
<!--Your Content-->
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'There are currently no upcoming events, please check back soon.' ); ?></p>
<?php endif; ?>
Hope that helps.
Ok, I got this to work. My code was actually working, I just was not able to pull in the parameter the way I originally wanted (or thought that I could). What I did was pass the Post ID parameter through the URL and then pull that parameter into my style template. Here is what I did in case it helps anyone in the future:
I passed the Post ID into the url (I.E. http://www.mysite.com/processform/?postid=1234).
I added this to my style template:
<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ;
$parts = parse_url($url);
parse_str($parts['query'], $query);
$mypostid = $query['postid'];
?>
and this is how my repeater fields looked:
<?php if(get_field('choice_menu', $mypostid)): $i = 0;?>
<?php while(has_sub_field('choice_menu', $mypostid)): $i++;?>
<p><?php the_sub_field('choice_name'); ?> : $check<?php echo $i; ?></p>
<?php endwhile; ?>
<?php endif; ?>
Thanks, Elliot.
My issue is that I am wanting to create multiple forms but use only one template to style the form, so what I want to do is pass the post id from multiple forms to the one template.
So lets say I have 5 different forms, when the user hits submit, I need to send the post id of that specific form over the one style template page (I am trying to avoid creating multiple style templates).
I can easily pull over the post id to the style template but I am not sure how (or if it is possible) to substitute the post id:
If I have this in the form:
<input name="Name" type="text" value="<?php the_sub_field('name'); ?>" />
I then pull in this field in the style template by using:
$Name
I can do something similar with the post ID and naming it $post_id
, I’m just not sure how (or if) I can then us that in the repeater below to pull in the specific post ID
<?php if(get_field('choice_menu', '$post_id'));?>
<?php while(has_sub_field('choice_menu', '$post_id'));?>
Is it possible? Does that make sense in what I am trying to do?
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.