1

I have a post type 'job_listing' and I want to use manage_{$post_type}_posts_columns filter in it. I tried manage_job_listing_posts_columns but it's not working because of the underscore in the post type.

The code I tried is:

  add_filter('manage_job_listing_posts_columns', 'add_more_column_to_post', 10, 1);

  function add_more_column_to_post ($posts_columns) {
    $posts_columns[ 'featured' ] = __( 'Select Featured Post' );
    return $posts_columns;
  }
  • I just did a quick test and it it works just fine with an underscore in the post type slug. Please post the relevant code-- you CPT registration function, your manage_ filter code, etc. – s_ha_dum Sep 29 '13 at 18:15
  • I tried with add_filter('manage_job_listing_posts_columns', 'add_more_column_to_post', 10, 1); function add_more_column_to_post ($posts_columns) { $posts_columns[ 'featured' ] = __( 'Select Featured Post' ); return $posts_columns; } But the column is not showing in the table for this post type in wp-admin – Mahesh Sep 29 '13 at 18:22
  • 2
    Your code works for me. There are details missing from this question, as least some of which I have asked for already and which you have still not included. The problem is somewhere in those missing details. – s_ha_dum Sep 29 '13 at 18:36
0

I had this exact same issue, but it's a problem with the Jobroller theme (seeing as the custom post type is job_listing, I'm guessing you're using Jobroller as well).

The Jobroller theme adds the custom columns to the job_listing custom post type using the function jr_edit_jobs_columns in the file jobroller/includes/admin/admin-post-types.php:

function jr_edit_jobs_columns( $columns ){
    $columns = array(
        'cb' => '<input type="checkbox" />',
        'title' => __('Job Name', APP_TD),
        'author' => __('Job Author', APP_TD),
        'job_cat' => __('Job Category', APP_TD),
        'job_type' => __('Job Type', APP_TD),
        'job_salary' => __('Salary', APP_TD),
        'company' => __('Company', APP_TD),
        'location' => __('Location', APP_TD),
        'expire_date' => __('Expire Date', APP_TD),
        'date' => __('Date', APP_TD),
        'logo' => __('Logo', APP_TD),
    );
    return $columns;
}

But this function does it incorrectly, it simply redefines the columns instead of adding and removing columns to the existing list. So any columns you add in a child theme will be removed before the page is rendered (Because child themes get executed first).

You should edit that function like so:

function jr_edit_jobs_columns( $columns ){
    $new_columns = array(
        'cb' => '<input type="checkbox" />',
        'title' => __('Job Name', APP_TD),
        'author' => __('Job Author', APP_TD),
        'job_cat' => __('Job Category', APP_TD),
        'job_type' => __('Job Type', APP_TD),
        'job_salary' => __('Salary', APP_TD),
        'company' => __('Company', APP_TD),
        'location' => __('Location', APP_TD),
        'expire_date' => __('Expire Date', APP_TD),
        'date' => __('Date', APP_TD),
        'logo' => __('Logo', APP_TD),
    );
    unset($columns['cb']);
    unset($columns['title']);
    unset($columns['author']);
    unset($columns['taxonomy-job_location']);
    unset($columns['taxonomy-job_cat']);
    unset($columns['comments']);
    unset($columns['date']);
    return $new_columns + $columns; // This way your custom columns are at the end
}
| improve this answer | |

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.