Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Last active February 10, 2016 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikejolley/9449528 to your computer and use it in GitHub Desktop.
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
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
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