Skip Navigation

[Closed] Limit Characters on Custom field

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 1 reply, has 2 voices.

Last updated by Adriano 9 years, 7 months ago.

Assisted by: Adriano.

Author
Posts
#244995

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

#245020

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.

The topic ‘[Closed] Limit Characters on Custom field’ is closed to new replies.