Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Created December 3, 2018 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/ac4a68769787352369ab0c5e41dc28ab to your computer and use it in GitHub Desktop.
Save cliffordp/ac4a68769787352369ab0c5e41dc28ab to your computer and use it in GitHub Desktop.
The Events Calendar: All Venue slugs get prefixed with a custom string. Works in wp-admin and Community Events.
<?php
/**
* The Events Calendar: All Venue slugs get prefixed with a custom string. Works in wp-admin and Community Events.
*
* !!! Change the prefix to your own !!!
*
* @link https://gist.github.com/cliffordp/ac4a68769787352369ab0c5e41dc28ab This snippet.
*/
function cliff_prefix_venue_slugs( $data ) {
// TODO: Change this to what you want!!!
$prefix = 'xvenue-';
if (
(
'publish' === $data['post_status']
|| 'draft' === $data['post_status']
|| 'pending' === $data['post_status']
)
&& class_exists( 'Tribe__Events__Venue' )
&& Tribe__Events__Venue::POSTTYPE === $data['post_type']
&& 0 !== strpos( $data['post_name'], $prefix ) // is not already prefixed, such as when moving from Deleted back to Published
) {
$data['post_name'] = $prefix . $data['post_name'];
}
return $data;
}
add_filter( 'wp_insert_post_data', 'cliff_prefix_venue_slugs' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment