I'm using Wordpress latest version, a child theme and Visual Composer WPBakery Page Builder.
I'm getting my blog posts listed into a template php file using WP_Query
and in that page I need to:
I need to echo/display/show just that text, but when I do the_content ();
it outputs the VC shortcodes in a row as a raw text with shortcodes and the text. I also need to limit the text for this to 250 chars.
Here is the code I have just for the content part:
<?php
$query = new WP_Query( array( 'post_type' => 'post' ) );
$posts = $query->posts;
foreach($posts as $post) {
?>
<p>
<?php
$char_limit = 250; //character limit
$content = $post->post_content; //contents saved in a variable
echo substr(strip_tags($content), 0, $char_limit);
?>
</p>
<?php
}
?>
Thank you in advanced.
H
I found a small solution to my issue with getting the post content made with WPBakery Page Builder into a php template file listing all posts - like a blog page. Probably there might be clever and better ways to do it, but this solved my problem.
<?php
$the_query = new WP_Query( array( 'post_type' => 'post' ) );
while ($the_query->have_posts() ) {
$the_query->the_post(); ?>
<!-- you may add more post content here
I just want to refer to the content, not meta content or custom fields -->
<p class="bowe-post-content-bloc">
<?php
$conteudo = get_the_content(); //get ALL content for the post
$padrao = array('(\[vc(.?)\])', '(\[/vc(.?)\])','(\[booom_baannng_anypostsharebuttons])'); //create a filter
$reparacao = preg_replace ($padrao, "",$conteudo ); //remove content based on filter
echo wp_trim_words ( $reparacao, 40, '...'); //display only 40 words
?>
</p>
<!-- you may add more post content here
I just want to refer to the content, not meta content or custom fields -->
<?php
}
wp_reset_postdata(); ?>