I have created a custom field on my custom post. Below is the code I am using for the custom field.
<?php
function wpt_add_thirdpartyvideo_metaboxes() {
add_meta_box(
'wpt_thirdpartyvideo_extra',
'Information',
'wpt_thirdpartyvideo_extra',
'partyvideo',
'normal',
'default'
);
}
add_action( 'add_meta_boxes', 'wpt_add_thirdpartyvideo_metaboxes' );
function wpt_thirdpartyvideo_extra() {
global $post;
// Nonce field to validate form request came from current site
wp_nonce_field( basename( __FILE__ ), 'thirdpartyvideo_extra' );
// Output the field
echo '<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td>Video Script here </td>
<td>
<div class="form-check">
<textarea name="thirdpartyvideoscript">' . esc_textarea( get_post_meta( $post->ID, 'thirdpartyvideoscript', true ) ) . '</textarea>
</div>
</td>
</tr>
</table>';
}
function wpt_save_thirdpartyvideo_meta( $post_id, $post ) {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
if ( ! isset( $_POST['thirdpartyvideoscript'] ) ) {
return $post_id;
}
$events_meta['thirdpartyvideoscript'] = esc_textarea( $_POST['thirdpartyvideoscript'] );
foreach ( $events_meta as $key => $value ) :
if ( 'revision' === $post->post_type ) {
return;
}
if ( get_post_meta( $post_id, $key, false ) ) {
update_post_meta( $post_id, $key, $value );
} else {
add_post_meta( $post_id, $key, $value);
}
if ( ! $value ) {
delete_post_meta( $post_id, $key );
}
endforeach;
}
add_action( 'save_post', 'wpt_save_thirdpartyvideo_meta', 1, 2 );
?>
I have tried to add some dummy content and it's working. Now I have to add the third-party video code which is script and HTML tags like below Third-party example.
<script src="//fast.wistia.com/embed/medias/s3lqfi0zn7.jsonp" async></script>
<script src="//fast.wistia.com/assets/external/E-v1.js" async></script>
<div class="wistia_embed wistia_async_s3lqfi0zn7" style="height:349px;width:620px"> </div>
If I add the above code then I am getting the below output
<script src="//fast.wistia.com/embed/medias/s3lqfi0zn7.jsonp" async></script>
<script src="//fast.wistia.com/assets/external/E-v1.js" async></script>
<div class="wistia_embed wistia_async_s3lqfi0zn7" style="height:349px;width:620px">&nbsp;</div>