6h8j5 6h8j5 - 6 days ago 6
PHP Question

mb_strimwidth on implode list

I have the following code which gets a list of terms and seperates them using a slash, e.g.

test/test/test

I want to limit that text to 28 characters, I have attempted to use

mb_strimwidth
but I get a Call to undefined function where the function name is the output of
$type_seperated
.

<?php
$term_list = wp_get_post_terms( get_the_ID(), 'type', array( "fields" => "names" ) );
$type_seperated = implode('/', $term_list);
if ( ! empty( $term_list ) ) : ?>
<?php echo mb_strimwidth($type_seperated(), 0, 28, '...'); ?>
<?php else : ?>
<?php _e( 'N/A', 'text-domain' ); ?>
<?php endif; ?>


Is this not possible? Does the $type_seperated output need to be a string? How do I do this?

Answer

Confirm that $type_seperated() function exists which return strings. If you mistakenly used parenthesis () then remove parenthesis which means it should be like <?php echo mb_strimwidth($type_seperated, 0, 28, '...'); ?>

Comments