Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #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

    #1148872

    Hey 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,
    Ismael

    #1149824

    Hi 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!
    Alessio

    #1149885

    Hi Alessio,

    Glad you got it working for you! :)

    If you need further assistance please let us know.

    Best regards,
    Victoria

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.