Support » Plugin: WP Job Manager » Adding "author" to the base URL

  • Resolved brunobaer


    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(
        $replace = array(
        $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)
  • Plugin Author Mike Jolley


    Looks like $user->user_nicename (the $user part) isn’t set. You just need to get the author via $post->post_author

    Thanks a lot. This was the first step which brought us to the solution. $post->post_author displays the author-ID in the permalink. We added the following to display author username:

    $user_info = get_userdata($post->post_author);
        $replace = array(

    and it works 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding "author" to the base URL’ is closed to new replies.