rewrite permalink rules
-
I am trying to do same thing in this documentation for company instead: https://wpjobmanager.com/document/tutorial-add-meta-data-resume-permalinks/
I am unable to get this working. Could you take a look at this and see what I am doing wrong?
function add_job_rewrite_rules(){ add_rewrite_tag( '%job%', '([^/]+)', 'job=' ); add_rewrite_tag( '%company_title%', '([^/]+)', 'company_title=' ); add_permastruct( 'job', 'jobs/%company_title%/%job%', true ); } add_action( 'init', 'add_job_rewrite_rules', 11 ); /** * Add data to the permalinks * @param string $permalink * @param WP_Post $post * @param bool * @return string */ function job_permalinks( $permalink, $post, $leavename ) { // Only affect resumes if ( $post->post_type !== 'job' || empty( $permalink ) || in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { return $permalink; } // Get the meta data to add to the permalink $title = get_post_meta( $post->ID, '_company_name', true ); // We need data, so fallback to this if its empty if ( empty( $title ) ) { $title = 'company'; } // Do the replacement $permalink = str_replace( '%company_title%', sanitize_title( $title ), $permalink ); return $permalink; } add_filter( 'post_type_link', 'job_permalinks', 10, 3 );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘rewrite permalink rules’ is closed to new replies.