I’ve got this working now with the following code. All I need to do now is pass my values from my Participants Database.
[insert_php]
$post_id = 100;
$author_id = 1;
$slug = ‘arctic-fern’;
$title = ‘Arctic Fern’;
$content = ‘Milford Haven Marina – Najad 391’ ;
$post_id = wp_insert_post(
array(
‘comment_status’ => ‘closed’,
‘ping_status’ => ‘closed’,
‘post_author’ => $author_id,
‘post_name’ => $slug,
‘post_title’ => $title,
‘post_content’ => $content,
‘meta_input’ => array(‘bgmp_address’ => ‘52.12345,-2.54321’,
‘bgmp_latitude’ => ‘52.12345’,
‘bgmp_longitude’ => ‘-2.54321’),
‘post_status’ => ‘publish’,
‘post_type’ => ‘bgmp’)
);
[/insert_php]
This is my finished function. Basically users input details of their boat into the website. Data is stored in Participants Database. The user also inputs the Lat and Long of their boat. The routine below creates a PlaceMarker page for the users details and the PlaceMarker is displayed on the Google Map. I have a lot of subscribers and as more users enter their details the number of PlaceMarkers grows.
[insert_php]
/* Update Members Details */
$current_user = wp_get_current_user();
$user_name = $current_user->user_login;
$user_id = Participants_Db::get_record_id_by_term(‘username’, $user_name);
$record = Participants_Db::get_participant( $user_id );
echo do_shortcode(‘[pdb_record tabs=true record_id=’.$user_id.’]’);
/* Update Najad Yacht Position and PlaceMarker */
$current_user = wp_get_current_user();
$id = $current_user->id;
$boatdata = Participants_Db::get_participant($id);
$boat_name = $boatdata[‘boat_name’];
$home_port = $boatdata[‘home_port’];
$model = $boatdata[‘model’];
$latitude = $boatdata[‘latitude’];
$longitude = $boatdata[‘longitude’];
if (!empty($boat_name) &&
!empty($home_port) &&
!empty($model) &&
!empty($latitude) &&
!empty($longitude) &&
($latitude <> ‘0’) &&
($longitude <> ‘0’) )
{
/* Find existing Post ID and delete Post */
$mypost = get_page_by_title($boat_name, ”, ‘bgmp’ );
$post_id = $mypost->ID;
wp_delete_post($post_id);
/* Create new PlaceMark */
$author_id = 1;
$post_id = wp_insert_post(
array(
‘comment_status’ =>’closed’,
‘ping_status’ =>’closed’,
‘post_author’ => $author_id,
‘post_name’ => $slug,
‘post_title’ => $boat_name,
‘post_content’ => $home_port.'<br />’.$model,
‘meta_input’ => array(
‘bgmp_address’ => $latitude.’,’.$longitude,
‘bgmp_latitude’ => $latitude,
‘bgmp_longitude’ => $longitude),
‘post_status’ => ‘publish’,
‘post_type’ => ‘bgmp’) );
}
else {echo ‘Information has not been entered…’;}
[/insert_php]