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

    (@mikejolley)

    I don’t think you can have /ID, but you can have -ID. See https://wpjobmanager.com/document/tutorial-changing-the-job-slugpermalink/#section-3

    Thread Starter MedTn

    (@medtn)

    Thx, a have added this but don’t work, help pls ??

    add_filter( 'submit_job_form_save_job_data', 'custom_submit_job_form_save_job_data', 10, 5 );
    function custom_submit_job_form_save_job_data( $data, $post_title, $post_content, $status, $values ) {
        $job_slug   = array();
    	// Prepend ID
    	if ( ! empty( $values['post']['post_ID'] ) )
    		$job_slug[] = $values['post']['post_ID'];
    	$job_slug[] = $post_title;
        $data['post_name'] = implode( '-', $job_slug );
        return $data;
    }

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Plugin Author Mike Jolley

    (@mikejolley)

    O, I’ve just realised my mistake here. The ID doesn’t exist at that point!

    We could perhaps use the base slug. That would make a URL look like this:

    yoursite.com/job/ID/post_name

    Here is the code for that:

    function custom_job_post_type_link( $permalink, $post ) {
        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(
        	'%post_id%'
        );
    
        $replace = array(
        	$post->ID
        );
    
        $replace = array_map( 'sanitize_title', $replace );
    
        $permalink = str_replace( $find, $replace, $permalink );
    
        return $permalink;
    }
    add_filter( 'post_type_link', 'custom_job_post_type_link', 10, 2 );
    
    function change_job_listing_slug( $args ) {
      $args['rewrite']['slug'] = _x( 'job', 'Job permalink - resave permalinks after changing this', 'wp-job-manager' ). '/%post_id%';
      return $args;
    }
    add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );
    Thread Starter MedTn

    (@medtn)

    Youpi, Work perfecty. THX ??

    Hi Mike Jolley,
    above code works perfectly for me , my new url is
    wordpress/detail/838/liberty-village-toronto-ontario-canada/
    i want to add .html at last
    wordpress/detail/838/liberty-village-toronto-ontario-canada.html

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Permalink : ID JOB in URL’ is closed to new replies.