I am developing a wordpress plugin make a filter with data from a new post and old post. If the post is publish the trigger have to read the meta and the feature image of the post. If the post already exist and the post is change from the draft to publish I can have the data. Is not the case when the post is new, I have the id but the data stay empty.
function getDataFromPost($new_status, $old_status, $post) {
if ($new_status === 'publish' && $old_status !== 'publish' && $post->post_type === 'rv-products') {
$data=[];
$data['id_unit']=$post->ID;
$data['title']=$post->post_title;
$data['url']=$post->guid;
$data['rv-manufacturer-brand']=get_concatenated_terms( $post->ID, 'rv-manufacturer-brand' );#multiple
$data['rv-types']=get_concatenated_terms2( $post->ID, 'rv-types' ); #multiple
$data['fuel-type']=remove_string_from_another(get_post_meta($post->ID, 'fuel-type', true),'fuel-');
$data['condition']=remove_string_from_another(get_post_meta($post->ID, 'condition', true),'va-');
$data['sleeps']=remove_string_from_another(get_post_meta($post->ID, 'sleeps', true),'sleeps-'); #min
$data['regular-price']=get_post_meta($post->ID, 'regular-price', true); #max
$data['years']=get_post_meta($post->ID, 'years', true); #min
$data['odometer']=get_post_meta($post->ID, 'odometer', true); #max
$data['weight']=get_post_meta($post->ID, 'weight', true); #max
$data['lenght']=get_post_meta($post->ID, 'lenght', true); #max
$data['FeatureImage']=get_the_post_thumbnail_url($post->ID, 'full');
#$thumbnail_id = get_post_thumbnail_id($post->ID);
#$full_image = wp_get_attachment_image_src($thumbnail_id, 'full');
#$data['FeatureImage'] = $full_image[0];
$data['logo']=wp_get_attachment_image_url( get_theme_mod( 'custom_logo' ), 'full' );
$data['cie'] = get_bloginfo('name');
printf($data)
}
}
add_action('getDataFromPost', 'getDataFromPost', 100, 3);