Thursday, June 30, 2022
HomeWordPress Developmenthooks - Add motion save put up when create and publish

hooks – Add motion save put up when create and publish


I attempt to use the hook save_post in my wp however I’ve an issue. I do that :

operate when_save_post_match($post_id, $put up){

if (isset($post->post_status) && 'auto-draft' == $post->post_status) {
    return;
}

if( 'match' == $post->post_type ){

    $id_match = get_post_meta( $post_id, '_select_match_from_db', true );

    $req = $bdd->put together('INSERT INTO posts_matchs (id_match,id_post) VALUES
        (
            :id_match,
            :id_post
        )
    ON DUPLICATE KEY UPDATE id_match = :id_match, id_post = :id_post');
    $req->bindParam(':id_match', $id_match);
    $req->bindParam(':id_post', $post_id);
    $req->execute();
    $req->closeCursor();
}
}
add_action('save_post', 'when_save_post_match', 10, 2);

After I create a customized put up “match”, the motion of inserting information into the db is NOT DONE. After I replace a customized put up “match”, the motion IS DONE.
After I create after which delete a put up match, the motion IS DONE.

I would love the motion to be taken after I create a customized put up match (and replace) and only for the revealed put up.

I do not perceive how to do that.

Any concept ?

Thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments