Skip Navigation

[Resolved] Show substring of custom field value

This support ticket is created 3 years 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 4 replies, has 2 voices.

Last updated by khairul-azmanA 2 years, 12 months ago.

Assisted by: Luo Yang.

Author
Posts
#2030421

In a View, I want to show the first letter of a value stored in a field of custom post that I've created using Toolset. I've tried to insert a PHP command (after Googling) into the loop but no value was returned.

I have fields author-lastname, author-firstname that I want the View to show. Assuming my data is "John" (author-firstname), and "Doe" (author-lastname), I want the output to be "Doe, J,...". However the result returned would only be "Doe, ,...". Below is the extract of my loop:

<wpv-loop>
[wpv-item index=other]
[types field='author-lastname'][/types], <?php echo substr('[types field='author-firstname'][/types]', 0,1); ?>,
[wpv-item index=last]
[types field='author-lastname'][/types], <?php echo substr('[types field='author-firstname'][/types]', 0,1); ?>
</wpv-loop>

What is the correct way to achieve this? Thanks.

#2030643

Hello,

You can create another shortcode for it, for example below ticket:
https://toolset.com/forums/topic/cannot-find-field-options-under-the-single-field-setting/#post-1886537

More help:
hidden link

#2036255

Thanks for your assistance and directing me to a possible solution.

I tried it and got it to partially work by;
1. inserting the mb-strimtitle add-shortcode command in the functions.php file,
2. using the mb-strimtitle shortcode inside a View and passing [types field='author-first-name'][/types] as an argument.

What works: the resulting page truncates the Author First Name to only the first letter
What doesn't work: The first letter is showing "#" instead of "J" if the author first name value is "John"

I tried out some edit on the View and found that it would work if I pass an absolute value such "John" as the argument, and would not if I pass [types field='author-first-name'][/types].

The shortcode [types field='author-first-name'][/types] itself would otherwise output as normal by itself without the mb-strimtitle command.

#2036267

The problem you mentioned above is abnormal, since it is a custom codes problem, please provide a test site with the same problem, fill below private message box with login details, also point out the problem page URL and where I can edit your PHP codes, I need a live website to test and debug, thanks

#2036397

While re-creating the website on a staging site to allow access to you, your suggested solution has apparently worked perfectly on the staging site! So my issue is resolved now, only I need to check my actual site. Maybe check that all my Toolset plugins are up-to-date etc. Thank you!

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