在Wordpress插件的the_content()中添加过滤器


Adding filter to the_content() on Wordpress Plugin

我试图用我的插件编辑每一个帖子,但是当我这样做时:

add_filter('the_content', 'my_the_content_filter', 20);
function my_the_content_filter($content)
{
    $content = 'a';
    // Returns the content.
    return $content;
}
我的帖子没有任何变化。我的single.php使用的是the_content()。

您可以使用下面的函数来更改文章的内容。

// Update post 37
  $my_post = array(
      'ID'           => 37,
      'post_content' => 'a'
  );
// Update the post into the database
  wp_update_post( $my_post );