WP Job Manager
[resolved] Adding "author" to the base URL (3 posts)

  1. brunobaer
    Posted 9 months ago #

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


  2. Mike Jolley
    Plugin Author

    Posted 9 months ago #

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

  3. brunobaer
    Posted 9 months ago #

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


You must log in to post.

About this Plugin

  • WP Job Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.