1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need assistance with a snippet for WP Job Manager

Discussion in 'Blogging' started by waterbasis, Apr 20, 2017.

  1. waterbasis

    waterbasis Jr. VIP Jr. VIP

    Joined:
    Feb 27, 2014
    Messages:
    187
    Likes Received:
    152
    Location:
    Your brain
    Hi,

    I am wondering if you're able to help me with the following WordPress customization. We're using the WP Job Manager plugin (https://wpjobmanager.com/) and I'd need a little help with a slug/permalink edit.

    In the documentation is an article available which explains the following: at the current situation links are generated as follows: domain.com/job/job-name. However, I need the following structure: domain.com/job-category/job-name.

    Please check: https://wpjobmanager.com/document/tutorial-changing-the-job-slugpermalink/

    The article explains this.. Please check the code on: Example: Adding the category to the base URL. When I remove the 'job' in the following code, the job listings are working fine, but the rest of my website returns in a 404 error (also after saving the permalinks). Could you help me out to get this working and for how much?

    $args['rewrite']['slug'] = 'job/%category%';

    To

    $args['rewrite']['slug'] = '%category%';

    I am looking forward to hear from you.

    Full code:

    Code:
    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;
    
       // Get the custom taxonomy terms in use by this post
       $terms = wp_get_post_terms( $post->ID, 'job_listing_category', array( 'orderby' => 'parent', 'order' => 'ASC' ) );
    
       if ( empty( $terms ) ) {
           // If no terms are assigned to this post, use a string instead (can't leave the placeholder there)
           $job_listing_category = _x( 'uncat', 'slug' );
       } else {
           // Replace the placeholder rewrite tag with the first term's slug
           $first_term = array_shift( $terms );
           $job_listing_category = $first_term->slug;
       }
       
       $find = array(
           '%category%'
       );
    
       $replace = array(
           $job_listing_category
       );
    
       $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/%category%';
      return $args;
    }
    add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );
     
  2. waterbasis

    waterbasis Jr. VIP Jr. VIP

    Joined:
    Feb 27, 2014
    Messages:
    187
    Likes Received:
    152
    Location:
    Your brain
    BUMP
     
  3. Julie85

    Julie85 Jr. VIP Jr. VIP

    Joined:
    Nov 27, 2016
    Messages:
    132
    Likes Received:
    17
    Gender:
    Female
    Hi, i think i could help you out with it. Send me a PM.