I followed the instruction on how to set up posting from front end.
It’s working except my site’s posts doesn’t really have titles and gets the title from the custom fields I set up in acf.
Here’s my wp_insert_post code
function my_pre_save_post( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new' )
{
return $post_id;
}
// Create a new post
$post = array(
'post_status' => 'publish' ,
'post_title' => get_post_meta($post->ID, "pickup_date", true). ' - ' .get_post_meta($post->ID, "leaving_from", true). ' to ' .get_post_meta($post->ID, "going_to", true),
'post_type' => 'rides' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
I think this part is the problem:
'post_title' => get_post_meta($post->ID, "pickup_date", true). ' - ' .get_post_meta($post->ID, "leaving_from", true). ' to ' .get_post_meta($post->ID, "going_to", true),
it doesn’t work. it doesn’t get the custom fields. I also tried to use get_field and the_field. Nothing has work yet.
Is there a way to make it work? Am I missing something?
Thank you.