Hello, title says it all: How do I limit the characters of a custom field when I query the post in a php template? Here is my code, I would like to limit the amount of characters in the "brief-bio" custom field:
$args = array('post_type' => 'feat-artist', 'posts_per_page' => 1, 'post__in' => get_option( 'sticky_posts' ), 'ignore_sticky_posts' => 1);
//Define the loop based on arguments
$loop = new WP_Query( $args );
//Display the contents
while ( $loop->have_posts() ) : $loop->the_post();
?>
<h4>Featured Artist</h4><span class="liner"></span>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php
$brief_bio = types_render_field("brief-bio", array("raw"=>"true","separator"=>";"));
//Output the bio
echo $brief_bio;
?>
Thanks!
Yan
There is a "count" argument to limit characters, but this is only available using Views shortcodes.
There is nothing in Types to help you with that, you will need to use default PHP functions, as strlen() and substr(), as types_render_field() returns a normal string when you use raw argument. See an example: http://stackoverflow.com/questions/3019285/limit-string-length
Please let me know if you are satisfied with my answer and if I can help you with any other related question.