Home › Forums › Calendar Products › Events Calendar PRO › Removing unlinked venues & organizers
- This topic has 7 replies, 3 voices, and was last updated 9 years, 1 month ago by
Cliff.
-
AuthorPosts
-
February 19, 2017 at 11:09 am #1241753
William
ParticipantIs there a way to remove all venues and organizers which aren’t currently linked to an event?
We’re running a large calendar and the admin often creates a new venue or organizer instead of using a saved one. While encouraging the admin not do this anymore, it would be helpful if we could somehow remove all the excess venues and organizers.
True, they wouldn’t be available as saved entries until the info was reentered, but at this point trying to determine which are not being used by going through and viewing them one by one isn’t really feasible (1500 venues, 2000 organizers).
The main reason is actually because we export the calendar each week for print. It’s just that week’s events, but because those events may reference any venue or organizer, we have to export all of them every time, and it’s getting rather slow. We export using WP All Export, which lets you select posts with WP Query. We just use:
'post_type' => array('tribe_venue','tribe_organizer'), 'post_status' => 'publish'So if there’s a way to sort out what’s linked and what isn’t at that step that would solve the immediate issue. But still, I think having a way to remove unused venues and organizers would definitely be useful for any user with a busy calendar looking to keep things streamlined, particularly regarding reusing the same venue and organizer info (same but slightly different so a simple duplicate search doesn’t work).
Thanks!
February 20, 2017 at 4:02 pm #1242524Cliff
MemberHi, William.
You could get an array of unique Venue post IDs and unique Organizer post IDs from the post_meta of your Events post types… then compare those post IDs to all the Venue post type post IDs and run wp_delete_post() for each one that is not used by an Event.
Of course, we always recommend restorable database and file backups before modifying anything on your site.
Please let me know how this goes for you.
February 22, 2017 at 8:10 pm #1244276William
ParticipantThanks! While working on this I ran into a snag, hoping you might be able to help me out.
When I try to grab the VenueID from all my event posts I get empty values. I tried grabbing a few hundred and that worked fine, so I worked my way up and found it cuts out at 2015 (the number, not the year). If I set posts_per_page or numberposts at that or fewer, I get values, but if I set it for more, I get all empty values.
I rigged up a demo page to show what’s happening. Here’s what it looks like with 2015:
http://upcal.staging.wpengine.com/lemme-see-yer-id/If I ask for home, all those values show up as empty.
1:
2:
3:
etc.Here’s the relevant snippet:
$event_ids = get_posts( array( 'post_type' => 'tribe_events', 'posts_per_page' => 2715, ) ); echo "<h2>Venue IDs</h2>"; $i = 0; foreach ($event_ids as $event) { $meta = get_post_meta($event->ID, "_EventVenueID", true); $i++; echo $i . ": " . $meta . "</br>"; }Any suggestions you might be able to offer would be most appreciated… thanks!
February 22, 2017 at 10:21 pm #1244315Cliff
MemberFirst, your posts_per_page should be -1 to be unlimited.
Second, I went beyond our normal support and created this shortcode for you. I tested and it worked for me, but it’s not guaranteed and you should use at your own risk:
https://gist.github.com/cliffordp/b9cde5ad57eecefca3bcd578fc5e6a61
(Of course, we always recommend restorable database and file backups before modifying anything on your site.)
Please let me know how this goes for you.
February 23, 2017 at 8:46 am #1244629Cliff
MemberJust FYI: I updated the gist’s code just now to include Venues/Organizers of all Post Statuses (not just Published).
March 11, 2017 at 9:32 pm #1253004William
ParticipantBadass!!!! Thanks for going above and beyond. Always great to read such well-commented code as well, makes for a good lesson every time.
March 13, 2017 at 4:28 pm #1253595Cliff
MemberI’m so glad to hear that!
You’re very welcome. 🙂
-
AuthorPosts
- The topic ‘Removing unlinked venues & organizers’ is closed to new replies.
