But no matter what I do (including resaving permalinks) the post ID never shows up.
The slug of the CPT is jobs and I have tried replacing various parts of the above code with the CPT slug, but it's not working for me.
Can someone tell/show me exactly what I need to do (i.e., where in the above code would I add the CPT slug jobs or which parts of it I would replace with the CPT slug jobs)?
Can you please ensure that in permalink settings, you have appended /%post_id% at end of the permalink used? Usually your permalink should be set to Post Name or another base.
Additionally, please try decreasing the priority for the filter below, so it is executed after other default filters and ensures the impact.
I probably wasn't clear enough in my original message.
I've got six different custom post types but I only want one of the six (called jobs) to show the post id in the permalink. All others should continue to simply show the post name.
I've added it to functions.php and have resaved permalinks and individual "jobs" posts, but the "jobs" post permalinks still show up without the post ID.
To confirm, "jobs" is the exact slug of the post type.
I have just tried adding post_id to the permalinks of 'jobs' CPT. It looks like there's only 1 possible way and that is to add '%post_id%' before the post name, like below:
<em><u>hidden link</u></em>
However, even to achieve this, I changed a little setting in your CPT as shown in attached image.
And added followings to your theme's functions.php:
I also observed there's something like 'courseware' is in use, which requires permalinks to be set to '%postname%' to work correctly. However, I am not sure if that's the reason, that %post_id% can't be appended in Settings -> Permalinks. Since setting this in there doesn't work but leads to a Bad Request (400).
I will suggest if the above mentioned work around doesn't work for you, you may want to contact with our Certified Partners at https://toolset.com/consultant/. They can work closely with you to help you build your custom solutions.
Please let me know if you would like me to revert all this implementation, in case if you don't want this to retain, thanks.
Actually when you use a customized logic of URL Rewrite for a CPT, it looses the default handling of WP for archive pages. There are 2 options:
A) You use this custom URL Rewrite logic, create a View to list all jobs with excerpt and link to single job pages, and insert view in a page named "Jobs". So when /jobs is requested, you see an archive.
B) You opt-out for the custom URL logic and standard archive page works.
I will suggest that using option A, creation of Jobs View and Page isn't a big deal. You can keep your current custom logic of %post_id% in place, as well as, can mimic the archive page.
Please notice I have also changed the custom URL logic a little bit for Jobs CPT, as "/jobs/%post_id%". Just to make it more understandable if you utilize the option A.