Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi,

    Can you explain a bit more about what you want to do? Do you want to mix posts & events together in the same “stream”? Thanks.

    Thread Starter jewpajarillo

    (@jewpajarillo)

    Yup, that’s it! They should be arranged in order of date of publish. But for the events, I only wanna show future events.

    To do that you’d need to write some custom code that can query the two types of posts (post and event) and do the date filtering you mentioned.

    This should help:
    https://codex.www.ads-software.com/Displaying_Posts_Using_a_Custom_Select_Query

    It’s possible there’s plugin that can do this for you too.

    Thread Starter jewpajarillo

    (@jewpajarillo)

    Thank you! I actually tried that and here’s my code:

    $today = date(‘Y-m-d’);
    $querystr = “
    SELECT * FROM $wpdb->posts
    LEFT JOIN wp_qfah7m_em_events
    ON ($wpdb->posts.ID = wp_qfah7m_em_events.post_id)
    WHERE (
    $wpdb->posts.post_type = ‘post’
    AND $wpdb->posts.post_status = ‘publish’
    )
    OR ($wpdb->posts.post_type = ‘event’
    AND wp_qfah7m_em_events.event_start_date >= ‘$today’
    )

    ORDER BY $wpdb->posts.post_date DESC
    “;

    $pageposts = $wpdb->get_results($querystr, OBJECT);

    I noticed that the excerpt is not showing up though. Is the excerpt function not working on custom queries?

    EM doesn’t support excerpts by default so you would need to add that first.

    Thanks

    Thread Starter jewpajarillo

    (@jewpajarillo)

    Actually, I’ve been seeing excerpt/content for events. But for the the posts, it’s not showing up. I think that’s because when I joined the 2 tables, the post_id field from the events table attribute is NULL and that may have been confused the the_excerpt() function? Isn’t the the_excerpt() function refers to the ID field from the posts table though?

    Thread Starter jewpajarillo

    (@jewpajarillo)

    Oh I know why! There are 2 post_content fields in the joined tables– one from the posts table and one from the events table. It’s getting the latter one for the content/excerpt function which is actually NULL.

    Anyway, thanks for all your help. I basically chose which fields I need so that will prevent from having duplicate fields.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Show only future events on home page (plus other posts)’ is closed to new replies.