Tell us what you are trying to do?
I want to limit the number of words in the display of a dynamic text. This is text in a bootstrap view. This works well until you change the search criteria. As soon as the criteria are changed and the corresponding items are displayed, a line of text or code appears on the screen.
Is there any documentation that you are following?
Yes : https://toolset.com/forums/topic/set-limit-number-of-words-or-character-for-custom-field-output-on-front-end-grid/
Is there a similar example that we can see?
hidden link
What is the link to your site?
hidden link
Hi,
Thank you for contacting us and I'd be happy to assist.
While I can see the issue on your website when the search is performed, I couldn't reproduce this on my test website.
I have the admin access details, but, I'll need your permission to download a clone/snapshot of the website, to investigate this on a different server.
regards,
Waqar
Hi Waqar,
Happy to hear from you, hope your well. You have the permission to download a clone.
regards,
Jean
Thank you for the permission and I've downloaded the duplicator package.
I'll be performing some tests and will share the findings accordingly.
Thank you for your patience.
Thank you for waiting.
During troubleshooting on your website's clone, I noticed that the custom shortcode that you are using from the other ticket is not compatible with AJAX requests, when the Elementor plugin is being used.
For this particular requirement, you can register a new custom shortcode:
function word_trim_custom_func( $atts, $content = null ) {
$a = shortcode_atts( array(
'words' => '18',
'more' => '...',
'field' => ''
), $atts );
$output = do_shortcode('[types field="'.$a['field'].'" output="raw" suppress_filters="true"][/types]');
if (!empty($output)) {
return wp_trim_words( $output, $a['words'], $a['more'] );
}
}
add_shortcode( 'word_trim_custom', 'word_trim_custom_func' );
And in your content template, you can use this new shortcode, like this:
[word_trim_custom_field words="20" more="...." field="mettre-un-tres-court-descriptif-2-lignes-maximum"]
In this example, I've used the field slug "mettre-un-tres-court-descriptif-2-lignes-maximum", but you can replace it with other text or WYSIWYG field slugs too.
Hi Waqar and thanks for your mail,
I did what you asked, I integrated the code in functions.php, and I integrated the shortcode in the tooset template as mentioned but instead of the text it's the code [word_trim_custom_field words="20" more="...." field="put-a-short-description-2-lines-maximum"] that displays...
I apologize as there were some typos in my last reply and the correct name for the shortcode was not used.
Here is the code with the correct shortcode name and you can replace it in your theme's "functions.php" file:
function word_trim_custom_field_func( $atts, $content = null ) {
$a = shortcode_atts( array(
'words' => '18',
'more' => '...',
'field' => ''
), $atts );
$output = do_shortcode('[types field="'.$a['field'].'" output="raw" suppress_filters="true"][/types]');
if (!empty($output)) {
return wp_trim_words( $output, $a['words'], $a['more'] );
}
}
add_shortcode( 'word_trim_custom_field', 'word_trim_custom_field_func' );
My issue is resolved now. Thank you!