• Resolved bryceondemand

    (@bryceondemand)


    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 );

    https://wordpress.org/plugins/wp-job-manager/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mike Jolley

    (@mikejolley)

    function add_job_rewrite_rules(){
    	add_rewrite_tag( '%job_listing%', '([^/]+)', 'job_listing=' );
    	add_rewrite_tag( '%company_title%', '([^/]+)', 'company_title=' );
    	add_permastruct( 'job_listing', 'jobs/%company_title%/%job_listing%', 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_listing' || 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 );
    Thread Starter bryceondemand

    (@bryceondemand)

    Thanks Mike. This did something, the url changed but I now have a page that tells me that it cannot be found. That goes for all job posts.

    Plugin Author Mike Jolley

    (@mikejolley)

    You must go to Settings > Permalinks and save or it won’t work.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘rewrite permalink rules’ is closed to new replies.