Articles of wp update post

I need to bulk update all wordpress posts on a scheduled time

I need to update all posts on my wordpress site on a scheduled time (every day). So I wanted to create a new page template which I can call everyday through a cronjob to update all the posts at once. I have already created the page and the cronjob, but the code I add inside […]

wp_update_post creating revisions instead of updating the post

I have been trying to update a post in the posts table but for some reason, it is creating a multiple number of revisions but not updating the main post. I have been trying hard for the last one day to figure this out but so far so luck with this. $post_meta_value = get_post_meta($unit_post_id, $post_meta_key.’_after_id’, […]

Programmatically change post visibility on save_post action return a 500

I’m trying to change the post visibility for my custom post type. On the edit.php screen the user can use a custom field to set the post type to normal or extended. That field shall work as abstraction for the post_status. However, running the following code inside the save_post action terminates as 500 Internal Server […]

Odd behaviour for the update button when displaying a WP_List_Table

I am currently trying to add a WP_List_Table to a metabox in the edit page of a custom type. The code is currently class Post_Table extends WP_List_Table { public function __construct() { parent::__construct([ ‘singular’ => __( ‘Post’, ‘sp’ ), ‘plural’ => __( ‘Posts’, ‘sp’ ), ‘ajax’ => false ]); } function get_columns(){ $columns = array( […]

How to show Published date and/or Modified date

My code is based on the underscores reference theme. I have a posted_on function as follows: function example_posted_on() { $time_string = ‘<time class=”entry-date published updated” datetime=”%1$s”>%2$s</time>’; if ( get_the_time( ‘U’ ) !== get_the_modified_time( ‘U’ ) ) { $time_string = ‘<time class=”entry-date published” datetime=”%1$s”>%2$s</time><time class=”updated” datetime=”%3$s”>%4$s</time>’; } $time_string = sprintf( $time_string, esc_attr( get_the_date( ‘c’ ) ), […]

Is there a before_save_post hook or something similar

I need to check the value of a post status before is changed during a post update or even bulk update. And then depending on that value, adjust other values of the post Example: Lets say I have a custom post status status-one status-two status-three I have post “A” who’s status is status-one. So when […]

Can't update WordPress Page if post_content is Empty

I’m having an issue with WordPress where the Page isn’t Updating if the Visual Editor is Empty. Here are the steps I am taking: Go to Pages Click on an existing page to Edit On the Edit Page screen, Remove all the text from the Visual Editor so that the Visual Editor is blank Click […]

Use /prefix/postname as a slug in post_name?

I have a custom field that I would like to use as the post’s slug. I’m able to get the custom field to be used as the slug for the post but I’m having problems attaching a /prefix/ before the postname. This is the code I have so far (If you want to use something […]

Mass Update lines of code for all posts

Bit of a conundrum today. I implemented some query string into my website so I’d like to retroactively update all my previous (600+) posts to update specific hyperlinks to include this query string. Example, most of my posts have code like this: <a data-name=”Dish Washer”>Dish Washer</a> Would it be possible to forcefully update all posts […]

What action hook updates post meta?

Is there an straight-forward example anywhere of using wp_update_post() to edit post_meta on the front end? I have not been able to find any good learning resources. What I want to do is display post meta in an input field and when a user clicks submit trigger wp_update_post();. Thanks!