WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Archive wp_posts.post_date query (8 posts)

  1. terrenceh14
    Member
    Posted 1 year ago #

    We have yearly archive posts appearing (post-type/events/2013/) but the posts are pulled in via post_date (e.g YEAR(wp_posts.post_date)='2013') rather than _event_date_modified in the postmeta table. The problem is that if an event was created in say 2012 but with a start date of 2013 it would show in the 2012 archive rather than 2013.

    Wondering if wp_posts.post_date should be set as the event start date or we override the WP select query to reference the correct fields?

    http://wordpress.org/plugins/events-manager/

  2. caimin_nwl
    NetWebLogic Support
    Posted 1 year ago #

    So just to clarify, you're saying that an event created in 2012 with an event start date in 2013 shows up in the 2012 yearly archives?

  3. terrenceh14
    Member
    Posted 1 year ago #

    Yes, that's correct.

    It looks like the query checks the post_date (which won't necessarily be the same as event date) and uses that to determine if it should appear. Here's the query that appears on /post-type/events/2013/.

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
    FROM wp_posts
    INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
    INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
    WHERE 1 =1
    AND YEAR( wp_posts.post_date ) = '2013'
    AND wp_posts.post_type = 'event'
    AND (
    wp_posts.post_status = 'publish'
    OR wp_posts.post_status = 'private'
    )
    AND (
    wp_postmeta.meta_key = '_start_ts'
    AND (
    mt1.meta_key = '_end_ts'
    AND CAST( mt1.meta_value AS CHAR ) < '1376524800'
    )
    )
    GROUP BY wp_posts.ID
    ORDER BY wp_postmeta.meta_value +0 DESC
    LIMIT 0 , 10

  4. angelo
    NetWebLogic Support
    Posted 1 year ago #

    Wondering if wp_posts.post_date should be set as the event start date or we override the WP select query to reference the correct fields?

    Post Date is Event Date as per @marcus says in this thread - http://wordpress.org/support/topic/plugin-events-manager-post-date-showing-as-event-date?replies=7

  5. terrenceh14
    Member
    Posted 1 year ago #

    I'm not clear on the point made by @marcus.

    On my install, if I add an event it's also added into wp_posts, the post_date of which is the publish date, rather than the event date. The event date is saved in the wp_postmeta table.

    The problem here is that when the WP archive queries the database, it pulls back all posts with a post_date matching the selected year, which is when the event (post) was published rather than event date.

    I tried adding the filter below without any luck. Reading that post it looks like this code is related to the presentation of the event date, rather than the actual query.
    remove_filter('the_date',array('EM_Event_Post','the_date'));

    Thanks

  6. philipjohn
    Member
    Posted 1 year ago #

    Hiya,

    As this is a standard WordPress archive page, it uses the standard WP_Query and treats the events as it would any other post type, hence why you will see the events listed according to post_date.

    To change this you'll either need to filter the main query using something like pre_get_posts, or provide your own solution using EM_Events::output()

    Cheers,
    Phil

  7. terrenceh14
    Member
    Posted 1 year ago #

    Thanks Phil, that's exactly what I was after.

    I used pre_get_posts to add a filter which reset the where clause to select the correct posts based on the _end_ts meta value.

    Cheers

  8. angelo
    NetWebLogic Support
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic