• Hi to everyone!

    I’m currently doing a migration from an old theme to a new theme, and I’m in a big trouble.

    My old theme (Newspaper from tagdiv) has a field with a Video option for the posts. When I put a video URL, the video shows at the begining of the post (magic!)

    Now, I want to migrate this video field to my new theme. For do that, first I have done a custom field on my new theme for insert the Video URL and show it on the posts. (and it works!)

    But my big trouble and the only problem that I have is when I try to export this field with WP All Export -Import plugin. I have this on MySQL Database “wp_postmeta“‘s table:

    INSERT INTOwp_postmeta(meta_id,post_id,meta_key,meta_value`) VALUES
    (213286, 18405, ‘td_post_video’, ‘a:1:{s:8:”td_video”;s:27:”https://vimeo.com/273779372″;}’),`

    How the hell I can “extract” the Vimeo URL and POst ID to do later the import to my new Video field on my new theme ??? I think this is an array or something else. I study MySQL, but this escapes my knowledge. Crazy!

    Thank you very much in advance.

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

Viewing 15 replies - 1 through 15 (of 21 total)
  • Technically, these fields are there in the database irrespective of the theme you are using. The admin interface might not display them, but they are there.

    There are multiple options for the transition:

    1. Keep the field as is, called td_post_video and use it with your new theme
    2. Search and replace the wp_postmeta.meta_key from td_post_video to your new field name. You could do this with phpMyAdmin SELECT * FROM wp_postmeta WHERE meta_key="td_post_video", run an export on the results of the query, search and replace with a text editor of your choice and then import them back with phpMyAdmin. I’d recommend steering clear of this choice if you don’t know what you are doing.
    3. Use custom PHP code to query relevant posts via get_posts/WP_Query, loop and fetch their meta via get_post_meta and then add another meta via update_post_meta

    What have you used to set up the new custom field on your new theme? Is it custom code or a plugin?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Thread Starter Jordi

    (@kukat)

    I was thinking that is imposible, but now I have hope.

    Thank you very much! I will try soon.

    Thread Starter Jordi

    (@kukat)

    Hi again. Now I’m on home.
    @valentinbora
    I used custom code.
    I have this on Functions.php

    /*
    **** Vídeo i VIA per a Diània ****
    */
    
    	
    add_action('add_meta_boxes', 'videoDiania');
    function videoDiania() {
        add_meta_box('video','Video','el_video','post','normal','high');
    }
    
    function el_video() {
        global $wpdb, $post;
        $value  = get_post_meta($post->ID, 'video', true);
        echo '<label>Vídeo</label>
        <input type="text" name="video" id="video" value="'.htmlspecialchars($value).'" style="width: 100px;" /> ';
    }
    
    add_action('save_post', 'guardar_video');
    add_action('publish_post', 'guardar_video');
    function guardar_video() {
    global $wpdb, $post;
    if (!$post_id) $post_id = $_POST['post_ID'];
    if (!$post_id) return $post;
    $price= $_POST['video'];
    update_post_meta($post_id, 'video', $price);
    }

    And this on single.php

    
    <?php $video= get_post_meta(get_the_ID(), 'video', true); ?>
    <?php echo $embed_code = wp_oembed_get( $video ); ?>
    • This reply was modified 4 years, 10 months ago by Jordi.
    • This reply was modified 4 years, 10 months ago by Jordi.

    Looks good to me. Good job!

    Could you please mark this topic/issue as Resolved?

    Thread Starter Jordi

    (@kukat)

    I’m trying to solve this, but it’s too hard. I want to unserialize first, because my new custom field isn’t an array.
    How I Can Unserialize this:

    https://postimg.cc/NyFzcbYv

    Without losing the POst ID associated?

    I’d set up a custom function to be called from single.php along the lines of:

    
    function my_get_video_embed($id) {
        $video = get_post_meta($id, 'video', true);
    
        if (empty($video)) {
            $video = get_post_meta($id, 'td_post_video', true);
    
            if (!empty($video) && !empty($video['td_video'])) {
                $video = $video['td_video'];
                update_post_meta($id, 'video', $video);
            }
        }
    
        return $video;
    }
    

    So in single.php you’ll call this instead, which serves to copy the old field to the new field if it can’t find a value for the new field.

    Thread Starter Jordi

    (@kukat)

    OMG!
    Thanks!
    Can these fields disappear with a database cleanup or something similar?
    Or will WordPress store them associated with the post forever?

    They won’t disappear, no worries. They are stored forever.

    Thread Starter Jordi

    (@kukat)

    Hello again and thanks a lot for your help,

    I put this on single.php:

      $video= my_get_video_embed($id); ?>
    <?php echo $embed_code = wp_oembed_get( $video ); ?>

    But i get a lot of warnings about arrays and strings:

    "Warning: parse_url() expects parameter 1 to be string, array given in /usr/home/diania.tv/web/wp-includes/rewrite.php on line 480 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/rewrite.php on line 489 Warning: explode() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/rewrite.php on line 497 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_match() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/class-wp-oembed.php on line 271 Warning: preg_split() expects parameter 2 to be string, array given in /usr/home/diania.tv/web/wp-includes/kses.php on line 1668 Warning: strtolower() expects parameter 1 to be string, array given in /usr/home/diania.tv/web/wp-includes/http.php on line 521 Warning: strtolower() expects parameter 1 to be string, array given in /usr/home/diania.tv/web/wp-includes/http.php on line 521

    Thread Starter Jordi

    (@kukat)

    Ouch! This topic was marked “Resolved”, but I have a little problem yet.

    You should pass the proper ID to the function:

    $video = my_get_video_embed(get_the_ID());

    Thread Starter Jordi

    (@kukat)

    @sterndata I see that if I put again this post with “not resolved”, it does not appear on the forum again.

    Thread Starter Jordi

    (@kukat)

    @valentinbora Thanks! I try.

    Thread Starter Jordi

    (@kukat)

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Extract a field from an array on MySQL DB on WordPress’ is closed to new replies.