-2

Lets say we have a connected user that access one of his post to replace some existing information in X fields that already exist with some new ones.

How could I manage to update the old ones with the new ones?

Example:

custom post type name = recipe
field trying to be updated with new content = $_POST['title']
2
  • 1
    have you tried wp_update_post()? Oct 22, 2013 at 13:42
  • that's what im actually testing ! thks for the tip.
    – pouki
    Oct 22, 2013 at 15:06

1 Answer 1

1

Solved.. I did it in 2 steps and it works perfectly!

if(isset ($_POST['new_title']) && $_POST['new_title'] != "")
                            {

                                $post_type = get_post_type( get_the_ID() );
                                $id_post = get_the_ID();                
                                $title = get_field('titre');

                                $postInfo = array(
                                    'post_type' => $post_type,
                                    'ID' => $id_post
                                );

                                $id = wp_update_post($postInfo);

                                update_post_meta( $id, 'titre', $_POST['new_title'] );

                                $new_title = $_POST['new_title'];

                                $new_elem = array(
                                    'post_type' => $post_type,
                                    'ID' => $id_post,
                                    'post_title' => $new_title
                                );

                                wp_update_post($new_elem);

                            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.