Skip to content

Instantly share code, notes, and snippets.



Last active Feb 10, 2016
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(
$replace = array(
$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' );

This comment has been minimized.

Copy link

@ninjoan 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.