While looking at the shortcode guide (see screenshot) I saw that you can limit the character output of the EXCERPT by doing something like this:
[wpv-post-excerpt length="30" count="word"]
but that same logic does NOT work with a multi line custom field?
Q1: Why not?
Q2: And how can I make that happen with a multiline field?
Q1: Why not?
I would assume it's because excerpt is a built-in WordPress feature. Themes and plugins use the excerpt in special ways. They willv apply their own rules for trimming and formatting the main post content to create the default excerpt.
https://wordpress.org/support/article/excerpt/
https://developer.wordpress.org/reference/functions/the_excerpt/
You can also create manual excerpts, not generated by the actual post content.
The multiline custom field isn't a WordPress concept, it's just one format in which Toolset can store custom field data. WordPress doesn't have built-in filters for this value. You can use a custom shortcode to produce a trimmed version of the field content if you'd like. Add this to your child theme's functions.php file, or to a new custom code snippet in Toolset > Settings > Custom Code:
function custom_trim_field( $atts, $content = null ) {
// Extract any arguments passed
extract( shortcode_atts( array(
'length' => 55, // Number of words to show
'more' => ' ...', // Text to show at the end of the filtered text
'field' => ''
), $atts ) );
global $post;
if ( empty($field) ){
return;
}
if ( !isset($post) ){
return;
}
$field = types_render_field($field, array("raw"=>"true"));
$excerpt_more = apply_filters('excerpt_more', $more); // Create excerpt length to excerpt_more filter
$output = wp_trim_words( $field, $length, $excerpt_more ); // create the filter text
return $output; // return filter text
}
add_shortcode( 'trimfield', 'custom_trim_field' );
Then you can use the shortcode like this:
[trimfield length="50" more="..." field="FIELDNICENAME"][/trimfield]
Replace 50 with the max word count, replace ... with whatever text you want to display at the end of any truncated value, and replace FIELDNICENAME with the slug of your custom field from wp-admin.