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.
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.
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
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!