Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to change all titles of posts from a specific category to a static one and don't want to change the rest. I have tried this code (based on this question but it doesn't work:

add_filter('wp_insert_post_data', function($data, $postarr) {

$args = array( 'category' => 36 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :
    $data['post_title'] = "New static title @ CurrentDate";
    $return $data;
}, 10, 2);

What is wrong? Thanks!

share|improve this question
I suppose you have 2 problems: 1) Modify all existing posts that match the criteria. 2) Do it for every new or modified post. Is this correct? – brasofilo Mar 12 at 10:57
Yes, that is correct. – Peleke Mar 12 at 11:04
Any advice? It works temporary with this code but I want it permanent function extra_title($title, $id) { if (in_category('6', $id)) { return 'Extra Title steht hier'; } return $title; } add_filter('the_title', 'extra_title', 10, 2); – Peleke Mar 13 at 8:59
The following Q&A's may give some food for thought: [1], [2] and [3]. – brasofilo Mar 13 at 13:50

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.