Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update WordPress Post Excerpt programmatically

Tags:

php

wordpress

I am looking for a function that can update the excerpts of already published WordPress posts. The function wp_update_post() does not update the excerpts. Other functions that I looked into like the_excerpt() are only for getting the excerpt instead of setting it.

How can I update the excerpts of published posts in WordPress?

like image 514
Real Noob Avatar asked Mar 03 '23 13:03

Real Noob


1 Answers

wp_update_post() should be the choice to use.

You can target the post_excerpt, in the $args, to address the Posts Excerpt.

An (untested, but should work) example:

$the_post = array(
      'ID'           => 37,//the ID of the Post
      'post_excerpt' => 'This is the updated excerpt.',
  );
wp_update_post( $the_post );

This is a very undynamic example but should give an idea about how to do it.

like image 141
Beda Schmid Avatar answered Mar 11 '23 02:03

Beda Schmid