-
AuthorPosts
-
October 15, 2019 at 6:49 pm #1148164
Hi,
I need to insert posts from outer source into my Enfold website using wp_insert_post() function.
I wrote a script that creates posts, and inserts some ALB shortcodes as content.Here is my PHP code:
—————————————————–
$post_arr = array(
‘post_content’ => $my_ALB_shorcodes,
‘post_title’ => $my_title,
‘post_status’ => ‘publish’,
‘post_type’ => ‘tribe_events’,
‘meta_input’ => array(
‘_aviaLayoutBuilder_active’ => ‘active’,
‘_aviaLayoutBuilderCleanData’ => $my_ALB_shorcodes,
),
);$the_post_id = wp_insert_post( $post_arr );
—————————————————–
So basically what I do is insert some shortcodes in each post ‘post_content’.
Please note that post type is set to ‘tribe_events’ because The Events Calendar by Modern Tribe is installed and I’m actually creating events.Now everithing works fine except for a little issue: the posts show some layout problems on front-end.
The strange thing is that the post layout in back-end is perfect and layout problems disappear if I save the post.
It looks like saving posts fixes their layout.I enabled ALB debug mode to check if the content in the post back-end do actually change after saving, but it is exactly the same.
So I took a look at wp_postmeta table in DB.
I found “_avia_builder_shortcode_tree” and “_alb_shortcode_status_content” new rows in wp_postmeta DB table after saving the post.
It looks like they contain serialized data that are inserted after saving.
Are that rows relevant for post layout?Any help?
Thank you
October 17, 2019 at 10:51 am #1148872Hey aledef,
Thank you for the update
How does the post look like initially? Try to update the post right after you created them.
// https://codex.wordpress.org/Function_Reference/wp_update_post
Or build the shortcode tree during the post creation.
$tree = ShortcodeHelper::build_shortcode_tree( $_POST['content'] ); Avia_Builder()->save_shortcode_tree( $post_id, $tree);
Best regards,
IsmaelOctober 21, 2019 at 11:59 am #1149824Hi Ismael,
It looks like updating the post via wp_update_post does’t recreate the shortcode tree.I solved the problem building the shortcode tree during the post creation.
Thank you!
AlessioOctober 21, 2019 at 2:51 pm #1149885Hi Alessio,
Glad you got it working for you! :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.