can't modify post title using the_posts filter

I tried to modify post title and content, content is modified in output, but title stays intact:

function filter_the_posts( $array , $oQuery) {
   ...
   $array[0]-post_title='new title';
   $array[0]-post_content ='new content';
   return $array;
}

add_filter( 'the_posts', 'filter_the_posts', 10, 2 );

Topic filters posts Wordpress

Category Web


You missed the return statement.

function filter_the_posts( $array , $oQuery) {
       ...
       $array[0]->post_title='new title';
       $array[0]->post_content ='new content';
       return $array;
    }
   
add_filter( 'the_posts', 'filter_the_posts', 10, 2 );

About

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