Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.