Skip Navigation

[Resolved] Custom meta with multiple values in views

This support ticket is created 3 years, 9 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.

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

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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1718585

Tell us what you are trying to do?
to use one selected meta field value in views query.

I ve custom meta:
_wcfm_affiliate_commission
with multiple values:
a:3:{s:4:"rule";s:8:"personal";s:12:"vendor_order";a:4:{s:4:"mode";s:0:"";s:7:"percent";s:0:"";s:5:"fixed";s:0:"";s:8:"cal_mode";s:7:"on_item";}s:5:"order";a:4:{s:4:"mode";s:7:"percent";s:7:"percent";s:2:"10";s:5:"fixed";s:0:"";s:8:"cal_mode";s:7:"on_item";}}
I want to display only selected value.
If I use shortcode
[wpv-post-field name='_wcfm_affiliate_commission']
I can see all values but I can't separate it.
Could you advise how to do this?

What is the link to your site?
hidden link

#1719079

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

The custom field value that you shared consists of the serialized data and it seems it was added by the "WCFM" plugin.

For the most efficient and future safe approach to extract individual values from this custom field, it would be best to consult the WCFM plugin's official support and documentation.
( these plugins normally offer built-in shortcodes or functions to safely get data from these custom fields )

If you'd like to use the custom PHP code, you can register a custom shortcode, that can extract the data from such a serialized field and show only the required part(s).

Example:


add_shortcode('show_seriealized_data_field', 'show_seriealized_data_field_func');
function show_seriealized_data_field_func($atts) {

	$a = shortcode_atts( array(
		'id' => '',
		'key' => '',
	), $atts );

	$custom_field_key = $a['key'];

	$output = get_post_meta( $a['id'],$a['key'],true);

	ob_start();
	
	echo "<pre>";
	print_r($output);
	echo "</pre>";

	return ob_get_clean();
	
}

This shortcode accepts two parameters:

1. "id" for the ID of the post to get the custom field value from.

2. "key" for the target custom field's key.

Example:


 [show_seriealized_data_field id='[wpv-post-id]' key='_wcfm_affiliate_commission']

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.