Created
September 8, 2015 17:55
-
-
Save cmunns/abbf41a618a703e07f15 to your computer and use it in GitHub Desktop.
PSU post_type_filter
This file contains hidden or 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 | |
add_filter('post_type_link', 'force_isle_category', 10, 2); | |
function force_isle_category($url, $post) { | |
$top_cat = null; | |
if ( class_exists( 'PSU' ) ){ | |
if ( 'product' == get_post_type( $post ) ) { | |
$product_cats = get_the_terms( $post->ID, 'product_cat' ); | |
foreach ($product_cats as $pc) { | |
if($pc->parent == 0){ | |
$top_cat = $pc; | |
break; | |
} | |
} | |
} | |
} | |
// if top level cat and is product append it to the permalink | |
if( $top_cat ) { | |
return '/'.$top_cat->slug.'/'.$post->post_name; | |
} else { | |
return $url; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment