Skip Navigation

[Resolved] Custom Shortcode Question … how to get a field name instead of it's value

This support ticket is created 3 years, 4 months 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 3 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#2144099

Hello.

I have a custom shortcode that will generate a URL to an archive page with a custom link name.

I have a custom radio button field that is set up like this:

Display Text | Custom Field Content
===========================
Category 1 Human Readable Name | 1
Category 2 Human Readable Name | 2
Category 3 Human Readable Name | 3
Category 4 Human Readable Name | 4

In the Shortcode, I am currently using this:
$links = get_post_meta( get_queried_object_id(), $link_url, false );

but this returns the number, i.e. 1/2/3/4.

Is there a way that I can get the radio button field LABEL (Display Text) instead of its VALUE (Custom Field Content)?

#2144437

Hello,

I assume the custom radio button field is created with Toolset Types plugin, you can try Types API function types_render_field():
https://toolset.com/documentation/customizing-sites-using-php/functions/

See the example codes for custom radio field:
https://toolset.com/documentation/customizing-sites-using-php/functions/#radio
click link "Usage examples"

#2144465

yes ... using the types plugin ...

are you saying that in my functions.php file I should change

$links = get_post_meta( get_queried_object_id(), $link_name, false );

to

	$links = get_post_meta( get_queried_object_id(), $link_name, true );

for this to work?

here is the whole function as of now (no change)

function my_archive_link_func( $atts ) {
	// Attributes
	$atts = shortcode_atts(
		array(
			'link_url' => '',
			'link_label' => '',
		),
		$atts
	);

	$link_url = $atts['link_url'];
	$link_label = $atts['link_label'];
	
	if ( ! $link_url ) return;	
	
	$links = get_post_meta( get_queried_object_id(), $link_url, false );
	
	$out = "";
	foreach( $links as $link ){	
		$out .= '<a href="/ibs/collection/' . strtolower(str_replace(" ", "-", str_replace(" / ", "-", $link))) . '/">' . $link_label . '</a>';
	}
   
	return $out;

}

add_shortcode( 'archive_link', 'my_archive_link_func' );
#2145507

As I mentioned above, Types API function types_render_field() can get the selected option label, for example:

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

See the document I mentioned above:
https://toolset.com/documentation/customizing-sites-using-php/functions/#radio