How to Edit Post Content Programmatically in WordPress
In this Article I am going to edit post content dynamically, with that existing content, I am going to add a footer text like, ” With regards, Author_name,” This not necessary here, but I am just taking it as example. First we need to query the posts using query_post and filter with certain parameters, than choose our necessary post, edit it.
<?php //here you need to specify the post id in-order to get the post to edit $kv_post = $wpdb->get_row("SELECT post_content,post_title FROM $wpdb->posts WHERE ID = 13"); //get the post title and content $kv_post_title = $kv_post->post_content; $kv_post_content = $kv_post->post_title; ?>
Now, you can print or edit the post title and content using the above two variables. $kv_post_title and $kv_post_content . Here you can simply pass the $kv_post_content and title to wp_editor and create editable fields. Else you can use php function to editing the content and upload it again by using wp_update_post(). Like the following example.
$kv_edited_post = array( 'ID' => 10, 'post_title' => $kv_post_title, 'post_content' => $kv_post_content ); wp_update_post( $kv_edited_post);
That’s it, Now you can edit your posts through programmatically. If you really like my article, Just follow me on below social sites and get more updates from me. If you have any doubt or require further clarification just comment it on next tab. Let me help you to fix it.