Home › Forums › Calendar Products › Events Calendar PRO › Display featured events with wp_query()
- This topic has 5 replies, 2 voices, and was last updated 9 years, 6 months ago by Brian.
-
AuthorPosts
-
November 11, 2014 at 3:14 am #876201vicdiluParticipant
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:
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íctorNovember 11, 2014 at 7:16 am #876626BrianKeymasterHi 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
November 12, 2014 at 5:37 am #879366vicdiluParticipantHi 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,
VictorNovember 12, 2014 at 7:49 am #879686BrianKeymasterYour 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
November 16, 2014 at 4:46 am #886775vicdiluParticipantHi 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:
Thanks,
VictorNovember 17, 2014 at 8:25 am #887810BrianKeymasterGreat, 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!
-
AuthorPosts
- The topic ‘Display featured events with wp_query()’ is closed to new replies.