Modify database after publishing post wordpress

2

I am working with Custom Post Type, creating classes and courses. When the course is scheduled as a draft it does not let me select it as the parent of the classes.

How can I do an UPDATE to specify the father at the ID level?

That is, by clicking on "Schedule class", the ID of your parent course will be automatically modified in the DB.

    
asked by lk2_89 26.12.2018 в 16:01
source

1 answer

1

In the end I'm doing it for WordPress functions. I have developed the following:

function guardar_padre($post_id){ $tipo_post = get_post_type($post_id); if ($tipo_post != 'curso'){ return; } else { $id_padre = get_field(pertenece); if($id_padre != 0){ wp_update_post( array( 'ID' => $post_id, 'post_parent' => $id_padre ) ); } } } add_action('post_updated','guardar_padre');

The problem is that when I give update to post, it stays loaded, as if entering an infinite loop that never ends. Even so, if I consult the BBDD, the change has been applied correctly.

What fails in my code that makes it enter that infinite loop?

    
answered by 30.12.2018 в 03:03