- This topic is empty.
-
AuthorPosts
-
June 1, 2012 at 1:48 pm #38312
mpoisel
MemberHi, I have a custom post type of ‘Events’ that have a custom fields for start date (startdate) and end date (enddate). I want to query them so that once an event happens it will it will disappear from the query. I’m not totally sure where to go with this, but any help would be appreciated. Thanks in advance.
This is the code that I have so far:
'events', 'posts_per_page' => 10 ); ?>
have_posts() ) : $loop->the_post();?>
ID, "postimg", true) ): ?>
ID, "event_date", true) ): ?>
ID, "event_date", $single = true); ?>
ID, 'startdate', true)));?> -
ID, 'enddate', true)));?>
ID, "event_location", true) ): ?>,
ID, "event_location", $single = true); ?>
current_post + 1) < ($loop->post_count)) {echo '';}?>
June 1, 2012 at 2:23 pm #103779ChristinaHooper
MemberThis is what I use:
$CustomValueVariable = get_post_custom_values(‘CustomValueVariable ‘, $post->ID);
June 1, 2012 at 4:39 pm #103782mpoisel
MemberI’m afraid I’m not following. What I want to happen is, when an event ends I want it to be removed from the events query.
June 1, 2012 at 5:15 pm #103785mpoisel
MemberI’ve been reading some forums and I think I got a little further, but haven’t had any luck
Here’s the new code:
";
$recent = array( 'post_type' => 'events', 'posts_per_page' => 10 );
$future = recent.'&order=ASC&orderby=meta_value&meta_key=startdate&meta_compare=>=&meta_value='.$today;
query_posts( $future );
if (!have_posts())
query_posts( $recent );
while ( have_posts() ) : the_post();?>
ID, "postimg", true) ): ?>
ID, "event_date", true) ): ?>
ID, "event_date", $single = true); ?>
ID, 'startdate', true)));?> -
ID, 'enddate', true)));?>
ID, "event_location", true) ): ?>,
ID, "event_location", $single = true); ?>
current_post + 1) < ($loop->post_count)) {echo '';}?>
June 4, 2012 at 9:07 am #103862ChristinaHooper
MemberIt sounds like all you need to do then is grab out the end date into a variable and then wrap your output code in an if statement so that it only outputs the events if the end date is less than the current date.
This website explains comparing dates:
http://www.highlystructured.com/comparing_dates_php.htmlSo you would have something loosely to the effect of:
WP_Query
Loop Posts
$EndDate = custom meta end date
if (currrent date is less than $EndDate):—- Spit out the post data —-
end if
End Loop Posts -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.