Last active
May 30, 2018 13:17
-
-
Save joshfeck/59695d72a11288d7246eb05c01a8e63b to your computer and use it in GitHub Desktop.
Jarred wanted custom permalinks for his events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
add_filter( 'post_type_link', 'jarred_show_ee_taxonomy_terms_in_permalinks', 1, 2 ); | |
function jarred_show_ee_taxonomy_terms_in_permalinks( $post_link, $post ){ | |
if ( is_object( $post ) && $post->post_type == 'espresso_events' ){ | |
$terms = wp_get_object_terms( $post->ID, 'espresso_event_categories' ); | |
if( $terms && is_array($terms)){ | |
return str_replace( 'events/%espresso_event_categories%', 'events/' . $terms[0]->slug , $post_link ); | |
} else { | |
return str_replace( 'events/%espresso_event_categories%', 'events/uncategorized', $post_link ); | |
} | |
} | |
return $post_link; | |
} | |
add_filter( 'FHEE__EE_Register_CPTs__register_CPT__rewrite', 'jarred_custom_events_slug', 10, 2 ); | |
function jarred_custom_events_slug( $slug, $post_type ) { | |
if ( $post_type != 'espresso_events' ) { | |
return $slug; | |
} | |
if ( $post_type == 'espresso_events' ) { | |
$slug = array( 'slug' => 'events/%espresso_event_categories%', 'with_front' => false ); | |
return $slug; | |
} | |
return $slug; | |
} | |
add_filter( 'FHEE__EE_Register_CPTs__get_CPTs__cpts', 'jarred_modify_event_espresso_cpt_archive_url' ); | |
function jarred_modify_event_espresso_cpt_archive_url( $cpt_registry_array ) { | |
if ( isset( $cpt_registry_array['espresso_events'] ) ) { | |
$cpt_registry_array['espresso_events']['args']['has_archive'] = 'events'; | |
} | |
return $cpt_registry_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment