Adding "author" to the base URL
-
We have read your documentation/tutorial on “Example snippet: Adding the Job ID to the base URL” because what we want to do is add the AUTHOR to the base URL.
However, we don’t get it right. This is what we did (you can probably spot the mistake?):function job_listing_post_type_link( $permalink, $post ) { // Abort if post is not a job if ( $post->post_type !== 'job_listing' ) return $permalink; // Abort early if the placeholder rewrite tag isn't in the generated URL if ( false === strpos( $permalink, '%' ) ) return $permalink; $find = array( '%author%' ); $replace = array( $user->user_nicename ); $replace = array_map( 'sanitize_title', $replace ); $permalink = str_replace( $find, $replace, $permalink ); return $permalink; } add_filter( 'post_type_link', 'job_listing_post_type_link', 10, 2 ); function change_job_listing_slug( $args ) { $args['rewrite']['slug'] = 'job/%author%'; return $args; } add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Adding "author" to the base URL’ is closed to new replies.