After I publish a post I want to get a custom field from the plugin advanced custom fields and store it inside a database. tried this:
function call_after_post_publish() {
$tcParentId = get_the_ID($post);
$tcParentTitle = get_the_title($tcParentId);
$tcChildTitle = get_field( "funcion_1_titulo_tc", $tcParentId );
global $wpdb;
$wpdb->insert(
'link',
array(
'parent_title' => $tcParentTitle,
'title' => $tcChildTitle,
'parent_id' => $tcParentId,
),
array(
'%s',
'%s',
'%d'
)
);
}
add_action( 'publish_post', 'call_after_post_publish', 10, 2 );
This doesn't seem to work because I think the function get_field() works only after the post is created. Is there other way I can get the custom field value?