Change fields after publish a custom post type

Support General Change fields after publish a custom post type

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #41166
    Christian KleeChristian Klee
    Participant

    Hello,

    I try to find a way to set a value after a custom post type is (first) published.
    This was my first try but it doesn't seem to work:

    add_action('transition_post_status', 'send_new_post', 10, 3);
    
    function send_new_post($new_status, $old_status, $post) {
        if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'cpt') {
              rwmb_set_meta( $post->id, "field_id", "test" );
        }
    }

    I could verify that $post->id is available within the if statement and that I will be inside the if statement, so is there a error with rwmb_set_meta?

    #41175
    PeterPeter
    Moderator

    Hello,

    If you want to use the function rwmb_set_meta() you need to hook the callback function to the action init with a priority later than 20 or a later hook than init. Or use the WordPress function update_post_meta().

    Please read more here https://docs.metabox.io/functions/rwmb-set-meta/#arguments

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.