Home › Forums › Calendar Products › Event Aggregator › Custom category based on event title
- This topic has 10 replies, 2 voices, and was last updated 6 years, 3 months ago by Ulla.
-
AuthorPosts
-
November 28, 2017 at 6:22 am #1393630UllaParticipant
Hello,
My organization uses a (1) Facebook page to alert members of a wide variety of upcoming events. Using the Event Aggregator these events are then imported to the website and displayed in the calendar there.
On the website I would like to structure the content a bit more; using a set of sub-pages and there displaying an Events Calendar Widget with relevant events.
To this end I am trying to add a category to each imported event depending on the content of the Facebook event (e.g. event title).
In essence I want to run something like this each time an event is imported:if (strpos($event_id, ‘beach’) !== false) {
wp_set_post_categories( $event_id, 102, true );
}Is that possible using the Event Aggregator?
Cheers!
November 29, 2017 at 12:42 pm #1395212VictorKeymasterHi Ulla!
Thanks for reaching out to us! Let me help you with this topic.
First, please let me note that we are fairly limited in how much support we can give for custom development questions like that.
That said, we always like helping out and at least point users into the right direction as much possible.
You can achieve what you are looking for with some custom coding. In the following thread, Barry provides an example of how you can use the ‘tribe_aggregator_before_insert_event‘ and ‘tribe_aggregator_before_update_event‘ filters to modify the arguments used in the creation/edit of the new event post > https://theeventscalendar.com/support/forums/topic/custom-function-on-event-import/
I hope that helps! Let me know if you have any follow up questions.
Best,
VictorDecember 1, 2017 at 5:43 am #1396542UllaParticipantThank you for the response.
I apologize if my question is outside the range of your assistance.The thread you linked was very helpful. I am still a bit lost however.
Using the skeleton Barry provided I was able to modify the imports. However, I can’t figure out how to target the event categories. I looked through the functions archive (https://theeventscalendar.com/functions/) but nothing stands out to me.
Is there some documentation that you could link that could help me?Thank you in advance!
December 1, 2017 at 2:47 pm #1396988VictorKeymasterHi Ulla!
I’m sorry you are a bit lost there. I’ve just realized that those filters I shared will not really help much for your specific need.
I’d suggest you take a look at the ‘tribe_aggregator_after_insert_posts’ action that fires after events and linked posts have been inserted in the database. You will find more about this action and the variables available to get the event information you’ll need in here > https://github.com/moderntribe/the-events-calendar/blob/master/src/Tribe/Aggregator/Record/Abstract.php#L1889
The function that you should probably use for your case is the wp_set_object_terms() > https://developer.wordpress.org/reference/functions/wp_set_object_terms/
I hope that helps you get started.
My apologies for the confusion, let me know if you have any other questions.
Best,
VictorDecember 7, 2017 at 4:08 am #1400166UllaParticipantThank you so much for you help so far Victor!
I am very close to getting the modification to work, but I have one last hurdle.
This is what I have so far:function add_custom_event_categories( $items, $meta, $activity ) { // Alter the event according to your needs foreach ($items as $item) { if (strpos($item, ‘golf’) !== false) { wp_set_object_terms( 6972, 'golftime', 'tribe_events_cat'); } if (strpos($item, ‘beach’) !== false) { wp_set_object_terms( 6415, 'beachtime', 'tribe_events_cat'); } } // Unhook remove_action( 'tribe_aggregator_after_insert_posts', 'add_custom_event_categories' ); } add_action( 'tribe_aggregator_after_insert_posts', 'add_custom_event_categories', 3);
It all works, it checks every entry that is getting imported/updated and if some part of the title matches the text it runs the wp_set_object_terms and adds the categories to the posts.
The last thing I would need help with is switching out whatever post-id I have hard-coded above (6972 and 6415) into whatever post is currently running through the loop. I have tried using $item and get_id(), but I can’t seem to get it working. The abstract.php you linked helped me out, but I’m still a novice in php and I can’t figure out how the event_id is stored.
How do I extract the event id from the parameters being passed in tribe_aggregator_after_insert_posts?Thank you in advance!
Cheers,
UllaDecember 8, 2017 at 5:35 am #1401154VictorKeymasterHi Ulla!
It seems you are pretty close to achieve that.
How do I extract the event id from the parameters being passed in tribe_aggregator_after_insert_posts?
That’s a great question. I can’t see a simple way to do it. I will reach out to the team to see if they can help with this and come back soon.
Please hang in there.
Thanks,
VictorDecember 27, 2017 at 2:31 am #1413138UllaParticipantThis reply is private.
December 27, 2017 at 6:30 am #1413184VictorKeymasterHi Ulla!
I’m sorry for the delay in getting back to you. I’ve been out for some time and just got back yesterday.
With the team help we’ve been able to come up with a more simple snippet using the ‘tribe_aggregator_before_insert_event‘ and ‘tribe_aggregator_before_update_event‘ filters in the end.
Try using the following snippet and let us know if it works for you:
https://gist.github.com/vicskf/47709449ff2a8b74c079a46a2931ede4
Best,
VictorDecember 28, 2017 at 6:17 am #1413806UllaParticipantIt works perfectly!
Thank you so much for your help, Victor.
You have been off great assistance. Say thanks to the team as well.Have a great New Year’s!
December 28, 2017 at 6:28 am #1413816VictorKeymasterI’m happy to be of help here 🙂 Thanks for following up to let us know it works for you.
I’ll close this thread now, but feel free to open a new topic if anything comes up and we’ll be happy to help.
Best wishes!
-
AuthorPosts
- The topic ‘Custom category based on event title’ is closed to new replies.