Skip to content

Instantly share code, notes, and snippets.

@mikejolley mikejolley/gist:9449528
Last active Feb 10, 2016

Embed
What would you like to do?
Post ID in job permalink - Must save permalinks after adding the code to functions.php
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' );
@ninjoan

This comment has been minimized.

Copy link

ninjoan commented Feb 10, 2016

Hello nice code mate but if i want the permalink like
E.g. /job/job-title/1234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.