• Hi,
    I am migrating a fairly largue wp site and changuing themes. The old theme has youtube videos embeded but the new one requires the youtube url to be entered into the custom field.

    Can anyone help me out? I can’t find a pluguin for this.

    The custom field’s key is ‘Iframe’ so I need to be able to guet from the the current post’s content the ” http://www.youtube.com/embed/xxxxxxx ” (src=”www.youtube.com/embed/xxxxxxx”) then use it to insert into the the custom field the value “www.youtube.com/embed/xxxxxxx” where the custom field’s key=iFrame

    Any help or pointer would be very much appreciated.

Viewing 1 replies (of 1 total)
  • Thread Starter Serensites

    (@serensites)

    I saw this but I must be missing something as it doesn’t insert the youtube linc into my custom field:

    add_action('save_post','guet_youtube');
    
    function guet_youtube($postID, $post) 
    
    $content = $_POST['guet_the_content'];
    if (preg_match('/http:\/\/www.youtube\.com\/embed\/([a-zA-Z0-9\-\_]{11})/', $content, $yturl) !='') {
    $ytid = substr($yturl[0], 25, 31);
    $custom = 'http://www.youtube.com/embed/'.$ytid.';
    update_custom_meta($postID, $custom ,'iFrame');
    }
    elseif (preg_match('/http(v|vh|vhd):\/\/([a-zA-Z0-9\-\_]+\.|)youtube\.com\/watch(\?v\=|\/v\/)([a-zA-Z0-9\-\_]{11})([^<\s]*)/', $content, $yturl) !='') {
    $custom = 'http://www.youtube.com/embed/'.$ytid.';
    update_custom_meta($postID, $custom ,'iFrame');
    }
    }
    
    function update_custom_meta($postID, $newvalue, $field_name) {
    // To create new meta
    if(!guet_post_meta($postID, $field_name)){
    add_post_meta($postID, $field_name, $newvalue);
    }else{
    // or to update existing meta
    update_post_meta($postID, $field_name, $newvalue);
    }
    }

    from here http://wordpress.org/support/topic/preg_match-from-a-custom-field

Viewing 1 replies (of 1 total)

The topic ‘Scan post for YouTube embed and insert into custom Field’ is closed to new replies.