Save values from a pre_post_update

The second attempt is closer to the result, as it is filer, not action, and you can return proper data. But code has several mistakes, I have fixed them. The proper number of parameters for the filter is 3. The first parameter is $data which should be modified and returned. It is the standard behaviour … Read more

Conditional for autosave or auto draft?

If you are using the save_post action hook; then you can prevent the code from executing during an autosave with the following conditional: function do_not_autosave( $post ) { // Check to see if we are autosaving if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) return; // Rest of the code here } add_action( ‘save_post’, ‘do_not_autosave’);

WordPress function saves a post twice and updates all posts

It duplicate because when you run the wp_update_post(), it will use the wp_insert_post() function and the action save_post will run again. please use the filter wp_insert_post_data to filter the value before save. https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data Example: function wpse309780_filter_post_data($data , $postarr) { $data[‘post_name’] = wp_count_posts( ‘post’ )->publish; return $data; } add_filter( ‘wp_insert_post_data’, ‘wpse309780_filter_post_data’ );

Clear cache on post of one type when something happens to post of other type

I suppose a quick and dirty way to achieve what you want is to clear the entire site cache, something like this: function clear_rocket_cache_on_post_save() { rocket_clean_domain(); } add_action( ‘save_post’, ‘clear_rocket_cache_on_post_save’ ); Otherwise you’ll need to do a query to get the matching post, something like this should work: function clear_rocket_cache_on_post_save( $post_id ) { // $result_id … Read more

save_post custom post type ? $_POST not working?

From what I can see there is no value set for ct_list_url2, when this code block executes, $meta = array(‘ct_download_link’, ‘ct_list_url’, ‘ct_list_url2’); foreach($meta as $dt) { if($dt == ‘ct_list_url2’) { $_POST[$dt] = get_blogspot_url($_POST[$dt]); } if(isset($_POST[$dt]) && $_POST[$dt] !== ”) { update_post_meta($post->ID, $dt, $_POST[$dt]); } else { delete_post_meta($post->ID, $dt); } … …in fact that goes for … Read more