Preface:
Ok, I know people are going to tell me
"use JavaScript"
To you people I'll say
"No! I don't want to!"
but I have a valid reason:
Problem overview:
I have a plugin which automatically creates a post and assigns the category "YouTube" - and gives it the post type "Video" whenever a new video is uploaded to a YouTube channel.
But in order for the post to display correctly on the website the Video ID ($_POST['_tern_wp_youtube_video']
) value needs to be placed in the $_POST['pukka[_pukka_media_url]']
input field (after the standard YouTube stuff).
Where I've looked:
Everywhere that tells me it can't be done unless I use JavaScript - but like I said - I don't want to use JS because it's not really a visual thing I'm trying to fix - it's a database thing.
What I've tried:
I'm kind of half way through this. I've collected all the information I need, I just need to find the way to manipulate the other fields value (without JavaScript):
add_action( 'publish_post', 'default_post_type' );
function default_post_type( $post_id ) {
if ( in_category( 'YouTube' ) ) {
// Change post_format to video
set_post_format( $post_id, 'video' );
// Get and combine values to create the YouTube watch URL
$youtube_pre = "http://www.youtube.com/watch?v="; // Set the YouTube watch URL prefix
$youtube_id = $_POST['_tern_wp_youtube_video']; // Get value of YouTube Video ID field
$youtube_value = $youtube_pre.$youtube_id; // Combine the two
}
}
So I've got the value that I want to enter ($youtube_value
), but I can't figure out how to do it with PHP. I was thinking to use str_replace()
- but that didn't work.