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.

  • You really need to show us how your input is created. I don't even understand if you are fetching data from user input or just via an HTTP request (are you running some cron jobs to import data)...
    – kaiser
    Feb 26, 2015 at 8:39
  • totally not clear what is the actual problem you are having. The background story is just distracting, what do actually want to do and fail at? Feb 26, 2015 at 9:43
  • On the create a post screen there is an input field called: "_tern_wp_youtube_video". This field value is automatically populated via the "Automatic Youtube Video Posts" plugin. The post is automatically published (hence the "Automatic Youtube Video Posts" name) - so I need to take this value and input it into the field called "pukka[_pukka_media_url]" so that the post displays properly.
    – Robodashy
    Feb 26, 2015 at 10:51


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.