Skip Navigation

[Resolved] Display with php custom field trimmed

This support ticket is created 8 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Luo Yang 8 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#353940

I am trying to:

With PHP (not shortcode), display a trimmed field.

I visited this URL:

hidden link

I can't figure out a way to display the trimmed field. wp-trim functions don't seem to apply to Types API fields, and I can't do complex shortcodes using "do_shortcode" function.

Here's my code so far:


function custom_do_grid_loop() {  
  	
	// Intro Text (from page content)

    
	$args = array(
		'post_type' => 'case-story', // enter your custom post type
		'orderby' => 'menu_order',
		'order' => 'DESC',
        'case-story-type' => 'homepage-slider',
		'posts_per_page'=> '10',  // overrides posts per page in theme settings
	);
	$loop = new WP_Query( $args );
	if( $loop->have_posts() ):
				
		while( $loop->have_posts() ): $loop->the_post(); global $post;

		echo '<div class="section-inner">';
        echo '<div class="slide-container">';
        echo '<div class="slide-image">' . types_render_field( "case-story-image", array( ) ) . '</div>';
        echo '<a href=""><div class="slide-caption"><h2 class="case-story">' . get_the_title() . '</h2><div class="caption-copy">' . types_render_field( "case-story-text", array( ) ) . '</div></div></a>';
        echo '</div>'; //end slide container
        echo '</div>'; //end section inner
		

         
         
		endwhile;
		
	endif;

}

Where it says
types_render_field("case-story-text",array())

I want to replace that with a trimmed field.

How do I do this?

Marisa

#353947

I actually need to trim the title, too, by character. but I'm guessing I'll know how once I see how to do the types field. But they might be different since the title is a default wp field.

#354021

Dear Marisa,

Are we talking about the wordpress function wp_trim_words()?
This function trims text to a certain number of words and returns the trimmed text.
https://codex.wordpress.org/Function_Reference/wp_trim_words

If it is, you can use it like this:
wp_trim_words(types_render_field( "case-story-text", array( ) ), 55, '.....')

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.