I'm reciving below data as SimpleXMLElement Object
SimpleXMLElement Object
(
[channel_id] => 5868
[account_id] => 5887
[tour_id] => 13
[tour_name] => Neuschwanstein & Linderhof Castle - Fast Lane
[tour_name_long] => Neuschwanstein & Linderhof Royal Castle and Oberammergau Tour from Munich - Skip-the-line
[tour_code] => MUC-MUC16
[time_type] => strict
)
And need to insert some fields in to a CPT called tours
$new_post = array(
'post_title' => $tour->tour_name_long,
'post_type' => 'tours',
'post_status' => 'publish',
'meta_input' => array(
'tour_id' => $tour->tour_id,
)
);
But getting the below error
Fatal error: Uncaught Exception: Serialization of 'SimpleXMLElement' is not allowed in /home/sgebgjhgdf/public_html/wp-includes/functions.php:626 Stack trace: #0 /home/sgebgjhgdf/public_html/wp-includes/functions.php(626): serialize() #1 /home/sgebgjhgdf/public_html/wp-includes/meta.php(94): maybe_serialize() #2 /home/sgebgjhgdf/public_html/wp-includes/meta.php(250): add_metadata() #3 /home/sgebgjhgdf/public_html/wp-includes/post.php(2522): update_metadata() #4 /home/sgebgjhgdf/public_html/wp-includes/post.php(4544): update_post_meta() #5 /home/sgebgjhgdf/public_html/wp-content/themes/unstrap/tour-sortcodes.php(63): wp_insert_post() #6 /home/sgebgjhgdf/public_html/wp-includes/shortcodes.php(355): tour_shortcode() #7 [internal function]: do_shortcode_tag() #8 /home/sgebgjhgdf/public_html in /home/sgebgjhgdf/public_html/wp-includes/functions.php on line 626
What am i doing wrong?
I need it to add a new post to the CPT called "tour" and add the meta field value called "tour_id"
OK, found the answer here for anyone whose looking for the solution: 'Serialization of 'SimpleXMLElement' is not allowed when saving in Wordpress post_meta