Support » Plugin: Pods - Custom Content Types and Fields » How to display pods items dated after a certain date/time

  • Resolved bryanhiggs

    (@bryanhiggs)


    Hi!

    I’m working on a custom post type of a church service (UUCM Service). I have managed to display all the services I’ve created, which show on the above linked page. The shortcode I used for that was:
    [pods name=”uucm_service” template=”UUCM Service Template” orderby=”service_date”]

    So far, so good. However, we have a need for two slightly different cases:

    1) Upcoming services — that is, display all the services with a service date beyond today’s date

    2) Next service — that is, we want to display only the next service (i.e. the first service whose date is beyond today’s date). We plan on displaying this in a prominent place on our front page.

    I’m stuck trying to figure out how to do the necessary where clause to accomplish these cases (the limit class can distinguish between them, of course)

    I appreciate any help you can give me.

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Jim True

    (@jimtrue)

    Upcoming is date based math, so you’ve got to use a where clause in your shortcode. I’ve found (because < and > get stripped out naturally by WP) that the best method for this is the between SQL operator.

    If you’re using post_date, you’re in luck, because it’s already a ‘date’; if you’re using a date field instead, it’s actually stored as text, which means yyyy-mm-dd hh:mm:ss format. You can flip the field to be treated as a date very simply though with the cast operator. So basically, assuming you have an event_date as the date we’re comparing:

    where="CAST(event_date.meta_value as DATE) BETWEEN CURDATE() and '2020/01/01'"

    I use the beginning of the next year as the end date of the ‘between’ test because it’s rare you need to show more than that into the future. CURDATE() is the MySQL command for the current date.

    For your ‘only show the next one’ add a limit=1 parameter to the above shortcode to only show the next entry.

    • This reply was modified 1 year, 1 month ago by Jim True. Reason: adding links to MySQL Documentation
Viewing 1 replies (of 1 total)
  • The topic ‘How to display pods items dated after a certain date/time’ is closed to new replies.