Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Events custom post type querying by start and end dates (wordpress)

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #38312
    mpoisel
    Member

    Hi, 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 '
    ';}?>

    #103779

    This is what I use:

    $CustomValueVariable = get_post_custom_values(‘CustomValueVariable ‘, $post->ID);

    #103782
    mpoisel
    Member

    I’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.

    #103785
    mpoisel
    Member

    I’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 '
    ';}?>
    #103862

    It 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.html

    So 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

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.