Display code snipplet based on event_date
-
Just getting started with this amazing tool!
I built a simple event pod to display past and future events. I want to include a code snipplet ( a ribbon ) that can be included in future events based on event_date field. Can someone point me in the right direction for conditional shortcode syntax based on event_date field? If that makes any sense…
Thanks!
-
Hi @fwunder
I’m sure this page will help you!
https://docs.pods.io/searching-filtering-sorting/complicated-where-sort-and-filters/using-date-based-searches/And if you are using the default WP_Query, please check it’s documentation!
https://developer.ww.wp.xz.cn/reference/classes/wp_query/Cheers, Jory
Jory,
Thank you so much for your advice! I still seem to be missing something.
I have a date field – event_date
My short code: `[pods name=”event” field=”event_ribbon” where=”CAST(event_date.meta_value as DATE) BETWEEN CURDATE() and ‘2024-01-01′”]’
event_ribbon is displaying on an event with event_date *before* current date.
Thanks in advance!
Hi @fwunder
Can you explain in what type of context you are using this shortcode?
Where is it placed?Cheers, Jory
Sure Jory,
It is a simple event (posts) loop in Elementor which displays past and upcoming events.
Pod ( event ) includes custom field ( event_date ). Field type is date and format is WordPress Default.
I am trying to display a custom field only if the event_date is between current date and sometime in future,
Experimenting a bit, I find that if I substitute event_date.meta_value with a date value it works as expected:
[pods name=”event” field=”event_ribbon” where=”CAST(‘2022-12-01’ as DATE) BETWEEN CURDATE() and ‘2024-01-01′”]
For some reason event_date.meta_value does not seem to be returning a value I would expect.
Thanks again!
Hi @fwunder
Then this is probably an Elementor issue.
It might be that the current post isn’t properly set within the post loop.You could try omitting the
nameattribute in the shortcode to make sure Pods will try to fetch the current object.[pods field=”event_ribbon” where=”CAST(‘2022-12-01’ as DATE) BETWEEN CURDATE() and ‘2024-01-01′”]Though I’m not sure whether the
wherefilter would work at that point. I honestly don’t thing so.Cheers, Jory
Thank Jory. I had tried that with no love. Returns “Pods embed error. Please provide a Pod name”
Trying to figure out how to return value of event_date.meta_value so I can see what is being seen.
Thanks,
Just to followup. I am trying to use the shortcode in a Loop Item Template.
I just discovered the event_date.meta_value used is the first event event_date ( lowest id=”3107″) instead of current post id/event_date.
Not sure how to make sure the shortcode is specific to the loop item.
Thanks.
Bottom line…when using Elementor templates need a method of getting pod (post) ID and passing to shortcode. Something like this in the template:
$id = get_the_ID();
echo “do_shortcode(‘[pods name=”event” id=”‘.$id.'” field=”event_ribbon”…]’);just spitballing
I just discovered the event_date.meta_value used is the first event event_date ( lowest id=”3107″) instead of current post id/event_date.
Indeed, could you try the
use_current=1option?
I think I remember that this didn’t work for Elementor since it does not uses the WP core functions for query loops but I’m not sure.Cheers, Jory
Jory,
Thanks so much for sticking with me on this. Getting close, but have another strange issue…
Pod event_date: 2022-06-29
shortcode in single post template: [pods field=”event_ribbon” use_current=”1″ where=”CAST(event_date.meta_value as DATE) BETWEEN CURDATE() and ‘2023-01-01′”]
It seems to be ignoring the date comparison as it returns field=”event_ribbon” with or without the comparison and even returns it if I replace event_date.meta_value with ‘2022-06-26’
thanks
Hi @fwunder
#post-16200436
Though I’m not sure whether the where filter would work at that point. I honestly don’t thing so.
I already thought this wouldn’t work.
I think you’ll need a custom function for this that will actually check the date before rendering the value.
You could use a helper function for this:
[pods use_current="1" field="event_ribbon" helper="validate_event_ribbon_date"]You can then create your logic with PHP:
function validate_event_ribbon_date( $value ) { if ( VALIDATE YOUR OBJECT HERE ) { return $value; } return ''; // Date not valid. }Cheers, Jory
The topic ‘Display code snipplet based on event_date’ is closed to new replies.