Support

Account

Home Forums General Issues get_field after publish_post in functions.php

Helping

get_field after publish_post in functions.php

  • Hi, im using this code to send an sms after a post type is published. but it doesn’t work, I receive “array” instead of “the field”. What is wrong with my code?

    Thanks

    function send_sms_post_publish( $ID, $post ) {
    
     require('twilio/Services/Twilio.php'); 
      
     $account_sid = 'X'; 
     $auth_token = 'Y'; 
     $client = new Services_Twilio($account_sid, $auth_token);
    
     $from = "+888888888";
     
       $celphone = "+99999999";
       $body = $ID.'--A--'.get_field( $ID, 'mensaje' ).'--B--'.get_post_meta( $ID, 'lista' );
       $client->account->sms_messages->create($from, $celphone, $body);
     
    }
    add_action( 'publish_envios', 'send_sms_post_publish', 10, 2 );
  • Hi,
    The get_field function expects the field name as the first parameter and the post if as the second parameter.
    I believe what you need to change is the

    get_field( $ID, ‘mensaje’ )

    get_field( 'mensaje',$ID)

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘get_field after publish_post in functions.php’ is closed to new replies.