How can I limit the text to say 100 characters from the get_post_meta tag?
I need to grab the text in this style:
<?php echo get_post_meta($relationship->ID, 'company_description', true ); ?>
This is how I would normally limit the text but I don't know how to combine it with the syntax above:
<?php echo substr($fields->company_description,0,100) . "..."; ?>
The most readable way:
$text = get_post_meta($relationship->ID, 'company_description', true);
echo substr($text, 0, 100) . "...";
Then of course, you could also nest the function calls, which probably sucks in terms of readability:
echo substr(get_post_meta($relationship->ID, 'company_description', true), 0, 100) . "...";
By the way: If company_description
might contain raw HTML, you'll probably want to run strip_tags()
over it before getting a substring – not stripping HTML would get you in trouble in the long run otherwise.
$text = strip_tags(get_post_meta($relationship->ID, 'company_description', true));
echo substr($text, 0, 100) . "...";