Last active
February 19, 2017 05:14
-
-
Save danjjohnson/6077095cd3f04fbc70b6c3914092d55e to your computer and use it in GitHub Desktop.
WP Job Manager: Append the post id to the permalink slug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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