Get the excerpt of post_content

Hi guys can you explain me how to get a excerpt length of 15 for the post_content in my code:

?php
$args = array( 'numberposts' = '2', 'tax_query' = array(
        array(
            'taxonomy' = 'post_format',
            'field' = 'slug',
            'terms' = 'post-format-aside',
            'operator' = 'NOT IN'
        ), 
        array(
            'taxonomy' = 'post_format',
            'field' = 'slug',
            'terms' = 'post-format-image',
            'operator' = 'NOT IN'
        )
) );


$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
    echo 
    'div class="news_home"
  div class="content_left"img src="'.get_permalink($recent['ID'])."'".get_the_post_thumbnail($recent['ID']).'/div
  div class="content_right"
    h4 '.   ( __($recent["post_title"])).'/h4
    span'. mysql2date('j.m.Y', $recent["post_date"]) .'/span
    div class="HR_ornament"
      hr class="news_hr"/
      div class="ornament_news"/div
    /div
    p class="news_text"'.( __($recent["post_content"])).'
            a href="' . get_permalink($recent["ID"]) . '"[...]/a 
    /p/div
/div 
';

Thank you in advance!

Topic post-content custom-content excerpt Wordpress

Category Web


I'm sure if you did some more research you would find this as it's been asked many times before.

If you just want all expert to return the value of 15 then you have to add something like this to your functions.php

// Customize excerpt word count length
function custom_excerpt_length() {
    return 15;
}
add_filter('excerpt_length', 'custom_excerpt_length');

This will make all excerpt return 15 characters.

Updated:

I don't see the_excerpt in your code so you will have to add this aswell

<?php the_excerpt(); ?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.