Follow us on
  1. Hi,

    I have successfully created meta box for posts. But when I *export* the WordPress XML content via WP Dashboard - Tools - WordPress Importer, I found that the post meta box data can not be *imported* to anther site via via WP Dashboard - Tools - WordPress Importer. The meta box is just empty.

    Here is my code:

    //
    // Create a metabox
    //
    CSF::createMetabox( $prefix_post_opts, array(
    'title' => 'Post Options',
    'post_type' => 'post',
    'show_restore' => true,
    'priority' => 'high',
    'context' => 'normal'
    ) );

    Is there any solution?

    Thanks!

    Posted 1 year ago #
  2. BTW, I found that meta box with iframe data can not be imported.

    XML is attached.

    Posted 1 year ago #

  3. Codestar
    Admin

    Hi,

    Sorry, this topic delayed cause it will be a complex answer.

    Firstly, The metabox framework has two database save option. "serialize" "unserialize".

    // Serialize saves data like this:
    {a:2 :{s:11:"Hello world";s:7 :":Another"}}
    
    // Unserialize saves like this:
    meta_data_name = Hello world
    meta_data_name = AnotherCopyCopied!

    "I think you know this, but I need to tell for easy understand."

    In this case I see you using serialize method and "textarea" field new line is problem... I mean this:

    // If you put a new line textarea, the serialize doesn't count correct.
    {a:2 :{s:10 :"Hello
    world";s:7 :":Another"}}
    
    It says 10 but there are 11 chars.CopyCopied!

    That is why importing xml data.

    Ok now, what is the solution ways ?

    You can return back to unserialize type. ( but all current data will gone, and you will re-code for your single.php get_post_meta things )

    Fix it manually like this for eg go to xml file:

    // from
    a:4 :{s:14:"opt-video-code";s:266:"<iframe width="782" height="440" src="https://www.youtube.com/embed/k2qgadSvNyU?&autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    ";s:12:"opt-duration";s:5 :"03:44";s:14:"opt-related-on";s:1 :"1";s:20:"opt-related-position";s:7 :"sidebar";}
    
    // to
    a:4 :{s:14:"opt-video-code";s:265:"<iframe width="782" height="440" src="https://www.youtube.com/embed/k2qgadSvNyU?&autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    ";s:12:"opt-duration";s:5 :"03:44";s:14:"opt-related-on";s:1 :"1";s:20:"opt-related-position";s:7 :"sidebar";}CopyCopied!

    I only changed s:266 to s:265 you can try modified xml version and see it work.
    Download

    You head mix ?

    Actually, this is not a framework issue. It's global issue. ( https://wordpress.stackexchange.com/questions/42360/with-wordpress-importer-why-cant-i-import-post-meta-containing-a-multi-dimensi )

    Let me say another solution:

    I think you don't need newline for opt-video-code textarea. Let's add a sanitize function for that textarea save.

    // add this to your utils.php or anywhere
    function wpenjoy_trim_newlines( $value ) {
      return str_replace( array( "\r", "\n" ), '', $value );
    }CopyCopied!
    // add sanitize function to option
    array(
      'id'       => 'opt-video-code',
      'type'     => 'textarea',
      'title'    => 'Video Code',
      'sanitize' => 'wpenjoy_trim_newlines',
    ),CopyCopied!

    And go to 70 posts and click to "update" button then export xml and try. it will take 10min.

    Regards, Codestar

    Posted 1 year ago #
  4. Wow! I didn't realize that this issue is so complex.

    Thank you so much for the solution!

    Posted 1 year ago #

  5. Codestar
    Admin

    You're welcome

    Posted 1 year ago #