Skip Navigation

[Resolved] Display with php custom field trimmed

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.

This topic contains 2 replies, has 2 voices.

Last updated by Luo Yang 5 years, 9 months ago.

Assigned support staff: 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

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

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, '.....')