Skip Navigation

[Resolved] Show custom field value after dividing it

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by fahimS-2 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2585007

I want to show a custom field value in my blog archive loop and in my post but I want to first divide it with 12 and then show it. Is there any way I can do it?

#2585845

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You will have to add custom shortcode where you should pass your field value and then the shortcode should return the divided value.

For example - you can add the following custom shortcode to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

function func_divide_and_show_value( $atts ) {
 
// Attributes
$atts = shortcode_atts(
array(
'value' => '0',
),
$atts
);
 
if($value) {
     $value = $value/12;
}
 
return $value;

}
 
add_shortcode( 'show_field ', 'func_divide_and_show_value' );

and you can call the above shortcode as:

[show_field value="[types field='field-slug' output='raw'][/types]"]

Where:"
- replace 'field-slug' with your original field slug.

#2589151
Screenshot_22.jpg
Screenshot_21.jpg
Screenshot_20.jpg

Hi there, I have tried the code but it isn't working for me.
You can check it here: hidden link

#2590343

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share admin access details and let me check whats going wrong with your setup.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2590991

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've adjusted the code added the "Custom Code" section as given under:

// Put the code of your snippet below this comment.
function func_divide_and_show_value( $atts ) {
  
// Attributes
	$atts = shortcode_atts(
		array(
			'value' => '0',
		),
		$atts
	);
  
  $value = $atts['value'];
  
	if($value) {
    	$value = $value/12;
	}
  
	return $value;
 
}
  
add_shortcode('show_field','func_divide_and_show_value' );

I can see its working as expected now: hidden link

#2591221

My issue is resolved now. Thank you!