Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created November 30, 2013 13:09
Show Gist options
  • Save mikejolley/7718889 to your computer and use it in GitHub Desktop.
Save mikejolley/7718889 to your computer and use it in GitHub Desktop.
Change job listing base slug in WP Job Manager - requires that permalinks are saved after adding to your theme functions.php file.
function change_job_listing_slug( $args ) {
$args['rewrite']['slug'] = _x( 'careers', 'Job permalink - resave permalinks after changing this', 'job_manager' );
return $args;
}
add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );
@Joe-Bloggs
Copy link

Hi Mike,

I was wondering if I could change the slug depending on what term in a taxonomy is the post assigned to. I'm using the "Job Types" and have 2 terms within this taxonomy. These are "Books" and "Magazines"

What I'm trying to achieve is that if the post has "books" term assigned to it, the slug would change to 'books' , but if the post has 'magazines' term assigned to it, the slug would change to 'magazines'

I've been trying to play around with the following function based on your example above:

function change_job_listing_slug( $args ) {
   $terms = wp_get_post_terms( $post->ID, 'job_listing_type' );
   foreach ( $terms as $term ) {
   if($term->name == 'books') {
   $args['rewrite']['slug'] = _x( 'books', 'Job permalink - resave permalinks after changing this', 'job_manager' );
   }
   elseif ($term->name == 'magazines') {
   $args['rewrite']['slug'] = _x( 'magazines', 'Job permalink - resave permalinks after changing this', 'job_manager' );
   }
   return $args;
   }
}

add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );

Unfortunately this doesn't work as expected. Would this be possible at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment