I have made a custom post type called news
that has meta boxes. I would like to print the data from the metabox as a excerpt. How can I do that?
This is the code that I use that prints the data :
<?php $loop = new WP_Query( array( 'post_type' => 'news', 'posts_per_page' => 10, 'post_parent' => 0 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_excerpt(); ?>
<p><?php echo get_post_meta( $post->ID, 'twpb_news_textdate', true ); ?></p>
<p><?php echo get_post_meta( $post->ID, 'twpb_news_rub', true ); ?></p>
<p><?php echo get_post_meta( $post->ID, 'twpb_news_textnews', true ); ?></p>
<?php endwhile; ?>
You could make use of
wp_trim_words
:Or, if you want the filters applicable to the regular excerpts to be used as well, write your own wrapper for it:
and then use
in your loop.