Support » Plugin: Events Manager » Archive wp_posts.post_date query

Viewing 7 replies - 1 through 7 (of 7 total)
  • caimin_nwl


    NetWebLogic Support

    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?

    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/.

    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



    NetWebLogic Support

    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 –

    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.



    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()


    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.




    NetWebLogic Support

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Archive wp_posts.post_date query’ is closed to new replies.