How to get a custom save_post function to return the default $post_id, $post, and $status for items with a post status of 'trash'?
Everything I return, no matter which way I try, spits out Warning: array_map(): Argument #2 should be an array in /post.php on line 1980
For items in the trash when restoring from trash or changing the post status if I play with different statuses. Seems like any return is just not returning the default array.
Need to get back to the basics here. Below is the code that works except for when restoring items from the trash, bugs out.
Thanks.
//add_action('init', array( $this, 'init' ), 10, 2 );
add_action( 'save_post', 'update_children', 10, 2);
function update_children( $post_id, $post ) {
if ( 'trash' != $post->post_status ){
// Is a top level post
if( 0 === $post->post_parent ) {
$children = array(
'post_parent' => $post->ID,
'post_type' => 'any', //you can use also 'any'
'fields' => 'ids', // Only Return IDs
'post_status' => 'publish',
);
global $post;
if ((is_array($children))&&(!empty( $children ))){
$the_query = new WP_Query( $children );
}
// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
$pages[] = get_the_ID();
//$pages = array();
if ((is_array($children))&&(!empty( $children ))) {
foreach( $children as $child_ids ) {
remove_action( 'save_post', 'update_children', 10, 2);
wp_update_post( $pages );
add_action( 'save_post', 'update_children', 10, 2);
}
}
endwhile;
endif;
}
}
}
save_post
that would cause this issue, so it's something you're doing. If we can see code that's causing the issue someone might be able to offer a solution. Without that it would just be a shot in the dark.wp_update_post
expects an associative array with elements that match the columns of the posts table.