Last active
February 10, 2016 23:15
-
-
Save mikejolley/9449528 to your computer and use it in GitHub Desktop.
Post ID in job permalink - Must save permalinks after adding the code to functions.php
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
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; | |
$find = array( | |
'%post_id%' | |
); | |
$replace = array( | |
$post->ID | |
); | |
$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/%post_id%'; | |
return $args; | |
} | |
add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello nice code mate but if i want the permalink like
E.g. /job/job-title/1234