Skip to content

Instantly share code, notes, and snippets.

@danjjohnson
Last active February 19, 2017 05:14
Show Gist options
  • Save danjjohnson/6077095cd3f04fbc70b6c3914092d55e to your computer and use it in GitHub Desktop.
Save danjjohnson/6077095cd3f04fbc70b6c3914092d55e to your computer and use it in GitHub Desktop.
WP Job Manager: Append the post id to the permalink slug
function custom_job_post_type_link( $post_id, $post ) {
// don't add the id if it's already part of the slug
$permalink = $post->post_name;
if ( strpos( $permalink, strval( $post_id ) ) ) {
return;
}
// unhook this function to prevent infinite looping
remove_action( 'save_post_job_listing', 'custom_job_post_type_link', 10, 2 );
// add the id to the slug
$permalink .= '-' . $post_id;
// update the post slug
wp_update_post( array(
'ID' => $post_id,
'post_name' => $permalink
));
// re-hook this function
add_action( 'save_post_job_listing', 'custom_job_post_type_link', 10, 2 );
}
add_action( 'save_post_job_listing', 'custom_job_post_type_link', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment