I have a frontend form through which users can create custom posts(events in my case).
Now I am want to fetch all address data
from that form and create a new post once that complete form is submitted by the user from the front end.
I am trying to use save_post to trigger my function in function.php
.
But below function gives 500 error in console
and the page is frozen.
add_action( 'save_post','add_menu_custom_event');
function add_menu_custom_event($post_id) {
//Check it's not an auto save routine
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
//Perform permission checks! For example:
if ( !current_user_can('edit_post', $post_id) )
return;
echo "post_id".$post_id;
$data = array (
'post_title' => 'New Title6',
'post_type' => 'tribe_venue',
'meta_input' => array (
'_VenueAddress' => 'Address check',
'_VenueCity' => 'city check',
'_VenueCountry' => 'Afghanistan',
'_VenueProvince' => 'province',
'_VenueZip' => '121007',
'_VenuePhone' => '7503118112',
'_VenueURL' => 'someurl.com',
'_VenueShowMapLink' => 1,
),
);
// save the new post
$pid = wp_insert_post($data,true); // gives 1536 _EventVenueID
update_post_meta( $post_id, '_EventVenueID', $pid ); // i am trying to link parent post id to its child post id
}