Skip to content

Instantly share code, notes, and snippets.

@yousufansa
Created February 8, 2019 07:41
Show Gist options
  • Select an option

  • Save yousufansa/fe2d8e56886ec2effbf867e01f081487 to your computer and use it in GitHub Desktop.

Select an option

Save yousufansa/fe2d8e56886ec2effbf867e01f081487 to your computer and use it in GitHub Desktop.
Jobhunt - Add Posted Jobs Count In Admin User Table
if ( ! function_exists( 'jh_child_add_user_table_column' ) ) {
function jh_child_add_user_table_column( $column ) {
if ( post_type_exists( 'job_listing' ) ) {
$column['jobs'] = esc_html__( 'Jobs', 'jobhunt-child' );
}
return $column;
}
}
add_filter( 'manage_users_columns', 'jh_child_add_user_table_column' );
if ( ! function_exists( 'jh_child_add_user_table_row' ) ) {
function jh_child_add_user_table_row( $val, $column_name, $user_id ) {
if ( post_type_exists( 'job_listing' ) ) {
switch ($column_name) {
case 'jobs' :
if( count_user_posts( $user_id , 'job_listing' ) > 0 ) {
$count_user_jobs = '<a href="' . admin_url() . 'edit.php?post_type=job_listing&author=' . $user_id . '">' . count_user_posts( $user_id , 'job_listing' ) . '</a>';
} else {
$count_user_jobs = count_user_posts( $user_id , 'job_listing' );
}
return $count_user_jobs;
break;
default:
}
}
return $val;
}
}
add_filter( 'manage_users_custom_column', 'jh_child_add_user_table_row', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment