0

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 );

1 Answer 1

0

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 );
1
  • return $array; was missing in this question, it exists in actual code. problem is somewhere else.
    – AVEbrahimi
    May 12, 2022 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.