Home › Forums › Calendar Products › Events Calendar PRO › How to get custom meta field from a recurring event?
- This topic has 9 replies, 2 voices, and was last updated 10 years, 2 months ago by
George.
-
AuthorPosts
-
March 9, 2016 at 12:33 pm #1086821
Erick
ParticipantI am having some trouble trying to get the value of a custom meta field from a recurring event. Bear with me as I lay out the whole problem.
I am making a page template that will list out a week’s worth of upcoming events. Here’s the “query” I’m working with:
$args = array( 'start_date' => $start_date->format('Y-m-d'), 'end_date' => $end_date->format('Y-m-d'), ); $events = tribe_get_events($args);$start_date is previously set up to be today’s date, and $end_date is set up to be 1 week after that. The foreach loop works fine with setup_postdata() and all, in that I can loop through a week’s events and retrieve basic post info like title, permalink, and excerpt.
However for recurring events I cannot get values from custom meta fields. This only happens if the event post was created after the meta field was created.
I’m using Advanced Custom Fields to set up the meta fields, “admission” and “events_tickets_url”. We set up a bunch of dummy events to work with while developing the site, and since then I added these two meta fields, meaning the posts were created before the meta fields. One of the recurring events is titled “HIGHLIGHTS TOUR”, where I used the “Edit All” link to update those two meta fields to “free with admission” and “https://google.com” respectively.
Then I can look through the individual instances of that event and the fields, and they do show that they have been updated. Like I can go to today’s instance of “HIGHLIGHTS TOUR” and the “events_tickets_url” field shows as “https://google.com”.
The crazy thing is though that in the foreach loop, get_field(‘events_tickets_url’) returns NULL as if the meta field doesn’t even exist. Even passing in the post ID of the current event in the loop to get_field() doesn’t work. It seems like whatever post ID I get from the post objects in the loop just isn’t the right ID to use in order to get a meta field. Or does the calendar plugin filter into get_the_ID() to return a different ID than normal?
In any case, I don’t really know what’s going on here. The only solution I have found is to create a new version of the event post, now that the meta fields already exist. But there’s gotta be a better way? What is the reason why I can’t get meta field values (at least from ACF) from recurring events, if the meta fields were created after the event posts?
In the screenshots I provided, the first shows one of the events being output during the foreach loop. These are meant to show that the meta field return as NULL during the loop, but if I edit the posts there is a value in that field.
March 9, 2016 at 12:39 pm #1086825George
ParticipantHey Erick,
Thanks for reaching out. I’m sorry to hear about some of the trouble here—one of the things that stood out to me in your write-up was your comment here:
One of the recurring events is titled “HIGHLIGHTS TOUR”, where I used the “Edit All” link to update those two meta fields to “free with admission” and
The “edit all” link does not usually allow meta-field customization—does ACF specifically add this functionality to WordPress?
If so, then maybe the issue is happening here, where the fields themselves were not updated as expected.
if you go to a single instance of a recurring event, for example, can you confirm that is actually has values for these fields? It sounds to me thus far that the fields just don’t have values on these singular recurring event instances.
Sorry if I’m wrong here—it’s just a potential culprit here, and worth confirming before exploring other options. Let me know what you think!
— George
March 9, 2016 at 1:02 pm #1086838Erick
ParticipantWow, thanks for the fast reply!
You know, now that I look through more of the instances, some of them have a value and some don’t. Actually on the third one I checked, a notification appeared at the top that “Recurring event data is still being generated for this event. Don’t worry, you can safely navigate away – the process will resume in a bit in the background.”
I guess it’s going through the future two year’s worth of instances still? Does that process hook into a WP cron? How long should this process take?
March 10, 2016 at 11:27 am #1087345George
ParticipantThanks for the feedback Erick!
That generation of recurring event data is indeed something hooked to WP Cron. It unfortunately won’t propagate custom meta, though, regardless. 🙁
In other words, that “edit all” feature that you mention, which let you try to add field values for many events at once, is NOT something that our plugins themselves provide, and so unfortunately they do not necessarily support it completely.
If you have two years worth of events, then the first few instances of recurring events might have the values generated fine, but then yes, once the events are “queued up” for generation in that process, the ACF “edit all” fields functionality does not sound like it’s picking up those later-generated events….
Does my description of things make sense here? It is essentially not possible for all meta values to be generated on all recurring event instances at once. 🙁
I’m sorry to bear all of this information—let me know what you think!
George
March 10, 2016 at 11:39 am #1087351Erick
ParticipantOK, so the “Edit All” feature doesn’t do custom meta fields. Does this carry over to the custom fields that the Events Calendar plugin itself provides? Instead of using ACF, I recreated the custom fields using the “Additional Fields” tab from the plugin’s settings. However, these seems to have the same problem in that “Edit All” doesn’t necessarily mean “Edit All” and the custom fields don’t update on the entire series of events.
Which fields can be updated via “Edit All”?
BTW, I should mention that I couldn’t find any documentation on how to pull the values for the custom meta fields created by the plugin. Like what the field name would be so I can run get_post_meta(). I only discovered the “_ep_custom_X” naming convention for these fields by looking through the postmeta table.
March 11, 2016 at 10:23 am #1087836George
ParticipantHey Erick,
Can you share a screenshot of this “Edit all” link you are referring to? I just think it would be helpful so that I can be 100% certain which link you’re referring to.
You can do so by uploading the screenshot to Imgur.com, Flickr.com, CloudUp.com, or any similar image-hosting site; then just share the links to those images here and I’ll take a look.
The reason I request this is because of your question here:
Which fields can be updated via “Edit All”?
I want to be sure I address the right link so I can answer this correctly.
Thank you for your patience here!
GeorgePS
I’m sorry to request a screenshot—we cannot log into customer sites for any reason, so I cannot log in and look firsthand. 🙁 The screenshot should be helpful, though—thank you for your patience!March 11, 2016 at 10:59 am #1087851Erick
ParticipantNo worries about the screenshot, actually I couldn’t give you a login if I wanted to because we only have the site on a local MAMP server at the moment. http://i.imgur.com/2xu2iGx.png
And I need to update you on something I discovered too, in that the guy who was creating these events may not have used the “recurring” feature on one post. I think he may have set up individual event posts and manually incremented the start date on each one, which would totally explain why “Edit All” wasn’t working like I thought it should.
I created some new events that I know are using the recurring feature properly, so I am going to test a few more things out as far as the meta fields are concerned.
March 11, 2016 at 11:21 am #1087865George
ParticipantThanks for this information Erick!
Custom fields that exist by way of ACF or other means may not be fully supported here—and we currently have no code that specifically ensures support for third-party custom fields.
However, I have just done some thorough testing with a recurring event series on my own site; the series is made of daily events for more than a year, so there are hundreds and hundreds of event instances.
If using PRO’s specific “Additional Fields” feature, as long as you let the “generating event data” loading screen finish its process, then I found no issue with either the initial generation of value for this field, OR with changing this field via “Edit All.”
In other words, on initial creation of the events, 100% of the events had the Additional Field’s value generated fine.
When updating the series via “Edit All,” 100% of the events received the updated value without issue.
I hope this information is helpful. We unfortunately do not support non-standard ways of generating recurring events, and cannot guarantee support in this way for ACF Fields or other custom fields—but I can confirm that our own implementation of “Additional Fields” works well.
Thank you,
GeorgeMarch 11, 2016 at 12:54 pm #1087927Erick
ParticipantI tested it out some more with event posts I made myself – yep, you are right! The meta field values do get saved to all events in a recurring series. Even the ACF fields work.
This whole thing must have started because the recurring events weren’t set up properly to begin with, which is our fault. Sorry about the headache!
March 11, 2016 at 1:48 pm #1087976George
ParticipantNo worries! Thank you for your patience here.
I’ll close this thread for now but don’t hesitate to open a new thread any time if other issues or questions arise. 🙂
Sincerely,
George -
AuthorPosts
- The topic ‘How to get custom meta field from a recurring event?’ is closed to new replies.
