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