• Resolved claren

    (@claren)


    I posted this in WordPress Developers but perhaps it belongs here. I’ve also reached out to PostX directly through their support page:

    I’m struggling to understand some confusing behavior with wp_update_post: a direct copy/paste of content completely corrupts a bunch of Gutenberg plugins.

    Example:

    // Get original post
    $my_post = get_post(POST_ID);
    $my_post_content = $my_post->post_content;

    // Copy the content and update the post with the same content
    $copy_post = array();
    $copy_post[‘ID’] =POST_ID;
    $copy_post[‘post_content’] = $my_post_content;
    wp_update_post($copy_post);

    If you do the above on a post that has a PostX Post Grid, for example, the PostX grids on the page will all be corrupted and broken. But I’m not sure why copying and pasting the post content should change anything.

    What am I missing? Thanks!

    The page I need help with: https://pastebin.com/79wVp1qB

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Anik Biswas

    (@anik4e)

    Hello,
    Yes you are right. PostX grid will be broken if you get post only. So you have to add common CSS and specific page CSS to the page.

    Add this filter for add Common CSS:
    add_filters('postx_common_script', '__return_true');

    Add this function to add Specific Page CSS:
    ultimate_post()->set_css_style(POST_ID);

    Thanks.

    Thread Starter claren

    (@claren)

    Hey thanks for responding.

    Unfortunately, that didn’t work for me, but perhaps I’m not understanding how to use it (I changed “add_filters” to “add_filter” because I assume that was a typo).

    My new code looks like this:

    
    add_filter('postx_common_script', '__return_true');
    
    // Get original post
    $my_post = get_post(POST_ID);
    $my_post_content = $my_post->post_content;
    
    // Copy the content and update the post with the same content
    $copy_post = array();
    $copy_post[‘ID’] =POST_ID;
    $copy_post[‘post_content’] = $my_post_content;
    wp_update_post($copy_post);
    
    ultimate_post()->set_css_style(POST_ID);
    

    This produces the exact same result, which is a corrupt Post Grid container. Mind pointing me in the right direction here again? I’ve never seen the ultimate_post() function and documentation isn’t easy to find. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_update_post breaks PostX Post Grids’ is closed to new replies.