we need to help WordPress a little with generating permalinks (out of the box, it won’t recognise the permastruct tag %product_cat%):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Inject term slug into custom post type permastruct. * * @link http://wordpress.stackexchange.com/a/5313/1685 * * @param string $link * @param WP_Post $post * @return array */ function wpse_5308_post_type_link( $link, $post ) { if ( $post->post_type === 'product_listing' ) { if ( $terms = get_the_terms( $post->ID, 'product_cat' ) ) $link = str_replace( '%product_cat%', current( $terms )->slug, $link ); } return $link; } add_filter( 'post_type_link', 'wpse_5308_post_type_link', 10, 2 ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.