Hello I am using the suggested snippet here to add a new term to a dropdown menu: https://wpjobmanager.com/document/applications-customising-application-statuses/

which is:

add_filter( 'job_application_statuses', 'add_new_job_application_status' );

function add_new_job_application_status( $statuses ) {
    $statuses['example'] = _x( 'Example', 'job_application', 'wp-job-manager- 
applications' );
    return $statuses;

That works fine but my new single entry 'example' is output at the bottom of the dropdown list, I'd really like it to be in 2nd place. Is there a simple way to do this? Thank you.

  • I don't believe this is a WP question, but a general PHP question about arrays, see stackoverflow.com/questions/3353745/… – Tom J Nowell Feb 18 '19 at 15:25
  • Thanks Tom, I wasn't aware if there might be nuances to executing this in a Wordpress functions.php file for this WP Job Manager plugin Applications add-on. Sunny's solution below works well though. – Ed A Feb 19 '19 at 8:08

You can achieve this by using the array_splice() function in conjunction with array_merge(). Here is an example:

function add_new_job_application_status( $statuses ) {
  return array_merge(
    array_splice( $statuses, 0, 1 ),
    array( 'example' => _x( 'Example', 'job_application', 'wp-job-manager- 
applications' ) ),
    array_splice( $statuses, 1, -1 ) 
add_filter( 'job_application_statuses', 'add_new_job_application_status' );

This function takes the first item in the $statuses array, your custom example field, the rest of the items in the array and merges it together. You need to do it this way as splice doesn't support inserting a multi-dimensional array at a specific point in an array. Hope that helps.

  • Excellent, new to me and concise code. I see this can be used to replace or just insert an additional entry which is great. Thanks. – Ed A Feb 19 '19 at 8:03

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.