Display featured events with wp_query()

Home Forums Calendar Products Events Calendar PRO Display featured events with wp_query()

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #876201
    vicdilu
    Participant

    Hi,

    I am working on a website using the events calendar plugin, and I would like to display some featured events on the homepage. To achieve this, I have made a checkbox custom field for the events post type called ‘home_featured’ and I am using the following code to show these featured events on the homepage:

    http://pastebin.com/eAWdN5Ve

    It’s working fine, but I wonder if there is a way to query only upcoming events (now it is showing both past and upcoming events as long as they are checked as home_featured). Now my client has to remember to uncheck the custom field when an event has finished.

    Any help would be appreciated.

    Thanks in advance,
    Víctor

    #876626
    Brian
    Keymaster

    Hi Victor,

    I can help you out here.

    If you add this to your coding it should just return future events.

    'eventDisplay' => 'list'

    I am not sure how that will work with getting both posts and events. You have have to get both individually and then merge the queries.

    Another bit of coding that may help is the meta_query found in this gist:

    https://gist.github.com/jesseeproductions/f7bdd1124e9c3fed5280

    Let me know if you have any follow up questions.

    Thanks

    #879366
    vicdilu
    Participant

    Hi Brian,

    Thanks for your prompt reply. The meta_query from the link has been very helpful.

    I made some attempts:

    On my first attempt ( http://pastebin.com/FRAwuPDX ), just removing ‘posts’ from the post_type in the wp_query worked, and only upcoming events were displayed, however, with this change, the event date -in line 21- was not working (I don´t know why?)

    On my second attempt ( http://pastebin.com/Yc7k5iVg ), I tried the meta_query and I mantained ‘posts’ in the wp_query, and now only upcoming events are being displayed and the event date is also working fine.

    In this query for my homepage, I am not getting posts, only events, so this second snippet is working well for me. For my home slider, I am making another similar query with posts and events, but in this case I can not filter by _EvenStartDate, as the post don’t have this custom field. In this case, the client would have to uncheck the ‘home_slider’once the event has finished. I will search a solution for this (maybe using conditionals) and I will post again with the solution, if I find any.

    Thanks for your support,
    Victor

    #879686
    Brian
    Keymaster

    Your welcome,

    I found this topic here on WordPress.org that may help you out. It shows how someone combined two different queries.

    https://wordpress.org/support/topic/multiple-queries-compiling-into-one-loop?replies=5#post-1920638

    That may help you out.

    Let me know if you have any follow up questions.

    Thanks

    #886775
    vicdilu
    Participant

    Hi Brian,

    Once again your suggestion has been very helpfull.

    I merged the two queries as in the topic you linked, and it wordked well.

    Here is the code, in case it can help someone in the future:

    http://pastebin.com/LbwPwbmZ

    Thanks,
    Victor

    #887810
    Brian
    Keymaster

    Great, glad it helps, I am going to go ahead and close this ticket, but if you need any other on something else please post a new ticket.

    Thanks!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Display featured events with wp_query()’ is closed to new replies.