Removing unlinked venues & organizers

Home Forums Calendar Products Events Calendar PRO Removing unlinked venues & organizers

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1241753
    William
    Participant

    Is 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!

    #1242524
    Cliff
    Member

    Hi, 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.

    #1244276
    William
    Participant

    Thanks! 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!

    #1244315
    Cliff
    Member

    First, 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.

    #1244629
    Cliff
    Member

    Just FYI: I updated the gist’s code just now to include Venues/Organizers of all Post Statuses (not just Published).

    #1253004
    William
    Participant

    Badass!!!! Thanks for going above and beyond. Always great to read such well-commented code as well, makes for a good lesson every time.

    #1253595
    Cliff
    Member

    I’m so glad to hear that!

    You’re very welcome. 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Removing unlinked venues & organizers’ is closed to new replies.