Skip Navigation

[Resolved] Render a user custom field in admin columns

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by jesperK 6 years ago.

Assisted by: Shane.

Author
Posts
#1195363
Skærmbillede 2019-02-04 12.53.43.png

I want a column with a sortable "Invoice and date" tab in the wordpress admin but my function does return the value.

function rudr_modify_user_table_row( $row_output, $column_id_attr, $user ) {
 
	$date_format = 'j M, Y H:i';
 
	switch ( $column_id_attr ) {
		case 'invoice_end_date' :
			return date( $date_format, strtotime( get_user_meta($user , 'wpcf-invoice_end_date',true ) ) );
			break;
		default:
	}
 
	return $row_output;
 
}

why?

#1195419

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jesper,

Thank you for contacting our support forum.

Taking a look at your code it doesn't seem to allow for your columns to be sorted.

What I recommend that you do is to try using the plugin below as it should be able to assist you to make your columns sortable.
https://wordpress.org/plugins/codepress-admin-columns/

Please let me know if this helps.
Thanks,
Shane

#1195433

Define column

 add_filter( 'manage_users_columns', 'rudr_modify_user_table' );
 
function rudr_modify_user_table( $columns ) {
 	$columns['invoice-date-end'] = 'Invoice date end'; // add new
 	return $columns;
 }

Value output:

add_filter( 'manage_users_custom_column', 'rudr_modify_user_table_row', 10, 3 );
 function rudr_modify_user_table_row( $row_output, $column_id_attr, $user ) {
 	$date_format = 'j M, Y H:i';
 	switch ( $column_id_attr ) {
        case 'invoice-date-end' :
            $date_invoice_date_end = get_user_meta($user)['wpcf-invoice-date-end'][0];
            if (isset($date_invoice_date_end)){
            return date('d-m-Y',$date_invoice_date_end);
            } else {
            return '-';
            }
			break;
		default:
	}
 
	return $row_output;
 
}

Sorting

add_filter( 'manage_users_sortable_columns', 'rudr_make_registered_column_sortable' );
 
function rudr_make_registered_column_sortable( $columns ) {
	return wp_parse_args( array( 'invoice-date-end' => 'invoice-date-end' ), $columns );
}

add_filter('wpv_filter_query', 'wpv_show_season_by_default', 99, 3);
function wpv_show_season_by_default( $query_args, $view_settings, $view_id ) {
    
    if($view_id == 14970 && !isset($_GET['wpv_view_count']) ){
        if( !isset($_GET['wpv_view_count']) || !isset($_GET['wpv_post_search'], $_GET['wpv-subject-lesson'], $_GET['wpv-level']))  {
            $query_args['post__in'] = array(0);
        }

     }
    return $query_args;
}