• Resolved chameleon29

    (@chameleon29)


    Is there a way to add a custom field to the post in wordpress that allows my authors to enter an ‘event date’ to the post and then have this plugin call all posts in the category ‘events’ but then put them in chronological order for all upcoming events? Also would like those events to perhaps drop off the list 7 days after an event date has passed. Could anyone give me an example for code to achieve this? Thanks in advance!

    • This topic was modified 6 years, 8 months ago by chameleon29.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter chameleon29

    (@chameleon29)

    Ok I was able to put in a plugin to help with the custom field bit that has the event date posted as mm/dd/yyyy with ‘Advanced Custom Fields’. Is it possible to order these from nearest upcoming date to furthest out and have the posts disappear 7 days after the event date?

    Plugin Contributor zymeth25

    (@zymeth25)

    Don’t worry about the front end output of dates in Advanced Custom Fields, that plugin stores all dates in YYYYMMDD format so it can be used for sorting.

    You need the customfield_orderby shortcode parameter, as per the docs:

    customfield_orderby – You can order the posts by a custom field. For example: [catlist numberposts=-1 customfield_orderby=Mood order=desc] will list all the posts with a “Mood” custom field. This parameter can be used toghether with customfield_name and customfield_value, you can use those parameters to select posts and then customfield_orderby to sort by this or another custom field. Remember the default order is descending

    So with the above you will have your ordering. What’s left is your 7 day expiry system. This is a bit complicated and cannot be sorted out just with LCP. My suggestions is to use something like [catlist id="3,-4" customfield_orderby="date"], this schortcode excludes category with id “4”, now you need custom code or a plugin that will automatically assign this category 7 days after event date and it will disappear from the list. Search for a plugin that can do that, or find someone who can code it for you, it should be easy for anyone who knows something about PHP.

    Cheers

    • This reply was modified 6 years, 8 months ago by zymeth25.
    • This reply was modified 6 years, 8 months ago by zymeth25.
    Thread Starter chameleon29

    (@chameleon29)

    Thank you so much! I will try these out when I get a chance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘orderby event date’ is closed to new replies.