add_action( 'publish_post', 'sm12_publish_post' );
add_action( 'save_post', 'sm12_publish_post', 20 ); //After save meta value
function sm12_publish_post( $postid ){
/** some checks */
if( "publish" != get_post_status( $postid ) )
return;
$post= get_post($postid);
$sub = 'test subject';
$mgs = 'test message';
wp_mail( 'test@gmail.com', $email, $mgs);
}
I need to get the custom fields to my frontend (Laravel) from WordPress Backend. The post was successfully saved, and I was able to get the Post ID and title, but I can’t fetch the values from custom field. Then after I var_dump the post data. It shows:
object(WP_Post)#1791 (24) {
["ID"]=>
int(789)
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2018-04-20 06:06:32"
["post_date_gmt"]=>
string(19) "2018-04-20 06:06:32"
["post_content"]=>
string(0) ""
["post_title"]=>
string(33) "Laundry Service - Quintessa Walls"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(31) "laundry-service-quintessa-walls"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-04-20 06:06:32"
["post_modified_gmt"]=>
string(19) "2018-04-20 06:06:32"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(65) "http://localhost/smartend/orders/laundry-service-quintessa-walls/"
["menu_order"]=>
int(0)
["post_type"]=>
string(6) "orders"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
{"id":789,"date":"2018-04-20T06:06:32","date_gmt":"2018-04-20T06:06:32","guid":{"rendered":"http://localhost/smartend/orders/laundry-service-quintessa-walls/","raw":"http://localhost/smartend/orders/laundry-service-quintessa-walls/"},"modified":"2018-04-20T06:06:32","modified_gmt":"2018-04-20T06:06:32","password":"","slug":"laundry-service-quintessa-walls","status":"publish","type":"orders","link":"http://localhost/smartend/orders/laundry-service-quintessa-walls/","title":{"raw":"Laundry Service - Quintessa Walls","rendered":"Laundry Service – Quintessa Walls"},"template":"","acf":{"customer_name":"Quintessa Walls","service_name":"Laundry Service","customer_phone_number":"+793-64-2761068","customer_email":"vyniqemo@mailinator.com","order_quantity":"501","order_date":"04/20/2018","order_notes":"Eum ab dolor ipsa non consequatur Repellendus Elit ratione ad ad totam qui ut vel culpa","order_status":"Pending"},"_links":{"self":[{"href":"http://localhost/smartend/wp-json/wp/v2/orders/789"}],"collection":[{"href":"http://localhost/smartend/wp-json/wp/v2/orders"}],"about":[{"href":"http://localhost/smartend/wp-json/wp/v2/types/orders"}],"version-history":[{"href":"http://localhost/smartend/wp-json/wp/v2/orders/789/revisions"}],"wp:attachment":[{"href":"http://localhost/smartend/wp-json/wp/v2/media?parent=789"}],"curies":[{"name":"wp","href":"https://api.w.org/{rel}","templated":true}]}}"
UPDATE:
The second bracket data, came from the response of th AJAX in my js. So get_posts() only return the first bracket {} which not includes the acf fields values.
My question is, how to get the data from the second brackets?
By the way, I’m using ACF to REST API so that I can get the acf data to my Laravel front end.