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)?
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"
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' );
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