Skip to content

Instantly share code, notes, and snippets.

@kish2011
Forked from danjjohnson/functions.php
Created February 19, 2017 05:14
Show Gist options
  • Save kish2011/17838bff05deff12f58fe08b6369ba5d to your computer and use it in GitHub Desktop.
Save kish2011/17838bff05deff12f58fe08b6369ba5d 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