0

I'm trying to edit the output of the filter (below) in the plugin WPJobManager. I want to make sure there isn't a duplicate company_name value in the $job_slug before it is updated. At the moment, its set to add company_name to the slug, but if you then edit the same post, it adds company_name again!

if ( apply_filters( 'submit_job_form_prefix_post_name_with_company', true ) && ! empty( $values['company']['company_name'] ) ) {
        $job_slug[] = $values['company']['company_name'];
}

I think I need to add a filter in my functions.php but I'm not sure how to do this with an IF statement to remove the duplicate. I was thinking something like this below? Could anyone point me in the right direction?

if ( strpos( $job_slug, sanitize_title($values['company']['company_name'];) ) ) {
            return;
        }
4
  • Looking at the code here, I'm not sure this is the source of your issue. The $job_slug is initialized as an empty array at line 756 (as of this writing), and the company name only gets prepended once.
    – Pat J
    Dec 31, 2020 at 17:34
  • Also, that filter passes only a boolean value, so $job_slug and $values aren't automatically available to any function you hook to it.
    – Pat J
    Dec 31, 2020 at 17:35
  • Thanks for the help Pat. I just want to stop the company name being added automatically again after the job is edited. Perhaps it's a bug with the plugin?
    – michael74
    Dec 31, 2020 at 17:45
  • 1
    It might be. Your best bet is to contact the plugin's support team.
    – Pat J
    Dec 31, 2020 at 19:07

1 Answer 1

0

i have created the following solution, it is working when you keep into the active theme functions.php.

Refrence
Page: includes\forms\class-wp-job-manager-form-submit-job.php
Line: 791

add_filter('submit_job_form_save_job_data', 'remove_dublicated_post_name', 10, 5);

function remove_dublicated_post_name($job_data, $post_title, $post_content, $status, $values){
 if( ! strpos( $job_data['post_name'] , sanitize_title($values['company']['company_name'] ) ){
    // to remove dublicate company names
    $post_name_raw_arr = explode("-",$job_data['post_name']);
    $post_name_unique_arr = array_unique($post_name_raw_arr );
    $job_data['post_name'] = sanitize_title( implode( '-', $post_name_unique_arr ) );
  }
return $job_data;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.