Change Wordpress content field with php

76 Views Asked by At

On a project of mine, i work with ACF (advanced custom fields), but due to some restrictions i can't just output the ACF, i need to get the output into the wordpress content field.

I actually have a solution that works, but it also brings some inconvenience with it, basicly it triggers a bunch of plugins that trigger on save post.

The code i run is the following

<?php
ob_start();
?>


a big template is here



<?php
$contents = ob_get_contents();
ob_end_clean();
ob_end_flush();
?>


<?php
$post = array();
$post['ID'] = $postnummer;
$post['post_content' ] = $contents;
wp_update_post( $post );
?>

Again, i would like to stress, that this code works. But i was wondering if there is a way to update the post_content without using the wp_update_post feature.

is something like the follow possible in some way or form?

update_post_meta( $post_id, 'wordpress_content', $contents );

Any help is greatly appreciated

1

There are 1 best solutions below

0
On

Why not use the the_content filter? It is specifically designed for such extensions of the original post content.