Skip Navigation

[Resolved] Display text instead of raw value?

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.

Our next available supporter will start replying to tickets in about 6.01 hours from now. Thank you for your understanding.

This topic contains 3 replies, has 3 voices.

Last updated by Caridad 6 years, 10 months ago.

Assigned support staff: Minesh.

Author
Posts
#278654

Hi.

Im trying to show my custom fields in the administration columns of a custom post type.

Its going well, and i can display my custom field values in the back-end 😀

Now, i have a problem though.. Some of my fields are radio buttons, so the value in the post listing is just showing 0,1 or 2 depending on the options of course..

How do i display the "Display text" that i defined in Types where i created the fields and the options?

Here is my code:


add_filter('manage_edit-festivalsdeltager_columns', 'my_columns_head');
	function my_columns_head($defaults) {
	$defaults['e-mail-adresse'] = 'E-mail';
	$defaults['aktiv-deltager'] = 'Aktiv deltager';
	return $defaults;
}

//Add rows data
add_action( 'manage_festivalsdeltager_posts_custom_column' , 'my_custom_column', 10, 2 );
function my_custom_column($column, $post_id ){
	switch ( $column ) {
		case 'e-mail-adresse':
		echo get_post_meta( $post_id , 'wpcf-e-mail-adresse' , true );
		case 'aktiv-deltager':
		echo get_post_meta( $post_id , 'wpcf-aktiv-deltager' , true );
		break;
	}
}

wpcf-aktiv-deltager is the one that is showing numberic value instead of display text..

Thank you.

#278787

Hi,
the value shown by the get_post_meta function is the raw value saved in the Database.

You may find useful to set the radio-button value in the Database to be show differently:
- Go to: Types >> Custom Fields
- Open Your custom fields
- Scroll to the radio-button fields and select "Show one of these values:"
- Insert the same strings as reported in "Display text" section

Or, you can use this:

types_render_field("my-radio", array())

to call the radio-button values from a PHP function.
For the full available options please refers to:
https://toolset.com/documentation/functions/#radio

#278793

Hi.

Im not sure if first solution is the way to go.. I already knew i was able to do so but i want to keep the values numberic for sorting and filtering.. also values dont go well when having too many special characters as far as i know, but PHP isnt my strong side unfortunately, so you know better than me if its a solid solution.

Alternatively, so i replace get_post_meta with types_render_field?

Thanks.

#278833

Let me explain this better, its not as easy as replacing.

types_render_field() is meant to be used in the frontend, not in admin.
So the first step is to add these few lines to allow using types_render_field in admin.

// Add support for types_render_field in admin
add_action( 'admin_init', 'admin_load_types' );
function admin_load_types() {
	require_once WPCF_EMBEDDED_ABSPATH . '/frontend.php';
}

Then you can replace like this:

add_filter('manage_edit-festivalsdeltager_columns', 'my_columns_head');
    function my_columns_head($defaults) {
    $defaults['e-mail-adresse'] = 'E-mail';
    $defaults['aktiv-deltager'] = 'Aktiv deltager';
    return $defaults;
}
 
//Add rows data
add_action( 'manage_festivalsdeltager_posts_custom_column' , 'my_custom_column', 10, 2 );
function my_custom_column($column, $post_id ){
    switch ( $column ) {
        case 'e-mail-adresse':
        echo types_render_field( 'e-mail-adresse' , array( 'post_id' => $post_id ) );
        break;
        case 'aktiv-deltager':
        echo types_render_field( 'aktiv-deltager' , array( 'post_id' => $post_id ) );
        break;
    }
}

Note that there was a missing break, I added it above.

Regards
Caridad