About changing the permalink structure
-
Hi,
I read your tutorial on changing the job’s permalink, but I can’t figure out how to do this (sorry, I know nothing about php). I’d like job_listing_category and job_listing_region to show in the URL before the listing name. I added the following to my functions.php, the job region shows in the URL but the job category doesn’t:
function job_listing_post_type_link( $permalink, $post ) { // Abort if post is not a job if ( $post->post_type !== 'job_listing' ) return $permalink; // Abort early if the placeholder rewrite tag isn't in the generated URL if ( false === strpos( $permalink, '%' ) ) return $permalink; // Get the custom taxonomy terms in use by this post $terms = get_the_terms( $post->ID, 'job_listing_category' ); $terms = get_the_terms( $post->ID, 'job_listing_region' ); if ( empty( $terms ) ) { // If no terms are assigned to this post, use a string instead (can't leave the placeholder there) $job_listing_category = _x( 'uncat', 'slug' ); } else { // Replace the placeholder rewrite tag with the first term's slug $first_term = array_shift( $terms ); $job_listing_category = $first_term->slug; } $find = array( '%category%' ); $replace = array( $job_listing_category ); $replace = array_map( 'sanitize_title', $replace ); $permalink = str_replace( $find, $replace, $permalink ); return $permalink; } add_filter( 'post_type_link', 'job_listing_post_type_link', 10, 2 ); function change_job_listing_slug( $args ) { $args['rewrite']['slug'] = 'job/%category%'; return $args; } add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );
What am I doing wrong?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘About changing the permalink structure’ is closed to new replies.