Page 1 of 1

PHP code to get a video URL and put it into video file field

Posted: Fri Aug 14, 2015 1:43 am
by steveryan
I recently purchased the WP User Frontend Uploader plugin.

The plugin works great, but there is one problem.

After upload, you have to go into the post edit page and manually place the video into the post from the media gallery so that it will display.

I've been working with the developers of the plugin to find a solution, but they aren't coming up with great ideas.

here is their latest suggestion: place the following code into the theme's function.php file.

Code: Select all

add_action('wp_head','test_get_post_meta');
function test_get_post_meta(){

    $data = wp_get_attachment_url( get_post_meta(3680, 'jtheme_video_file','true') );
    var_dump($data);
}
I think they are getting close with this little bit of code. The problem is that they have put the number "3680" into the code. 3680 is the attachment ID number of a specific video. That's not what I need! I need any video being uploaded to display instantly.

In order to do that, the code needs to get the video URL and send it to a field titled "jtheme_video_file"

Does anyone have any idea how to edit this bit of code so that the URL will get to the jtheme_video_file field where I need it?

Thanks for any help.

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 6:10 am
by Celauran

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 6:14 am
by Celauran
Also, your true should be a boolean, not a string.

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 12:35 pm
by steveryan
It's not the video ID number that we need. It's the URL.

The URL needs to automatically go into the jtheme_video_file field.

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 12:55 pm
by Celauran
So hardcoded ID notwithstanding, the code you listed above doesn't work at all? Is that what you're saying?

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 2:44 pm
by steveryan
Celauran wrote:So hardcoded ID notwithstanding, the code you listed above doesn't work at all? Is that what you're saying?
It doesn't work at all. It actually messes with my landing page as well. Puts the video URL into the header. It just sits up there doing nothing.

The developers I'm working with are in India and I don't think the completely understand what I need. I have a thread going on their website that's almost 4 pages long and I think they still just don't get it.

All were trying to do is build a YouTube type web site where people can upload videos on the front end. The videos are supposed to publish live on the site automatically after upload. That's all were trying to do.

In order for this to happen, the URL must go into the jtheme_video_file field. Instead, the attachment ID# goes in there. The ID# wont play the video. I has to be the URL.

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 2:52 pm
by Celauran
In order for this to happen, the URL must go into the jtheme_video_file field. Instead, the attachment ID# goes in there. The ID# wont play the video. I has to be the URL.
But get_post_meta will get you that value, and wp_get_attachment_url should then get you the correct URL. What is it returning instead?

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 8:31 pm
by steveryan
Celauran wrote:
In order for this to happen, the URL must go into the jtheme_video_file field. Instead, the attachment ID# goes in there. The ID# wont play the video. I has to be the URL.
But get_post_meta will get you that value, and wp_get_attachment_url should then get you the correct URL. What is it returning instead?
All it does is create the post. It titles the post the same as the title of the video (chosen by the user on the front end). Problem is that the video simply does not display. You have to manually insert the video into the post from the media gallery.

The purpose of the plugin is to allow users on the front end to upload either a photo, a file or a video and have a post automatically generated when they click "Submit". It's just a quick way for someone to create a post and have in image or video file or some other type of file attached to it. For whatever reason, the video does not show up. The developer of the plugin says "I'm sorry, but the plugin does not offer the functionality to automatically display a video. We will consider implementing it in the future." However, they have submitted the issue to their developer and he is trying to find a way around this. I don't think the developer himself actually understands what I need though. That's why he put the attachment ID# into the code he made. The guy just doesn't get it.

The code he gave me is also causing a problem on our landing page.

If you click the link to our site, you can see the issue it's causing on our landing page. It's inserting the URL above the header in the upper left hand corner.

http://www.10minutetv.com

In reality, there should be a simple way around this. I just need some code that will grab the URL and send it to a field.

Re: PHP code to get a video URL and put it into video file f

Posted: Fri Aug 14, 2015 9:00 pm
by Celauran
That's var_dump. It's doing that because you told it to. You can also see, however, that it's returning the URL as expected.

Re: PHP code to get a video URL and put it into video file f

Posted: Sun Aug 16, 2015 1:11 am
by steveryan
So it's returning it to the wrong spot then?

Any idea on how to get it to the field where I need it?

Re: PHP code to get a video URL and put it into video file f

Posted: Sun Aug 16, 2015 6:37 am
by Celauran
It's not returning it at all, it's just spitting it out. Now that you can see your function does what it's meant to, replace var_dump with a return statement and call the function where you need it. Also get rid of that add_action line.

Code: Select all

function getVideoURL($post_id) {
    $url = wp_get_attachment_url( get_post_meta($post_id, 'jtheme_video_file','true') );
    return $url;
}
Then, within your template

Code: Select all

$id = get_the_ID();
$video_url = getVideoURL($id);
and just echo $video_url where you need it.

Re: PHP code to get a video URL and put it into video file f

Posted: Sun Aug 16, 2015 10:23 pm
by steveryan
Okay great. Thank you for all your help. Just need to clarify a couple of things.

Put this in the functions.php file?

Code: Select all

function getVideoURL($post_id) {
    $url = wp_get_attachment_url( get_post_meta($post_id, 'jtheme_video_file','true') );
    return $url;
}
and then stick this in the template? I'm not sure what you mean by template.

Code: Select all

$id = get_the_ID();
$video_url = getVideoURL($id);

Re: PHP code to get a video URL and put it into video file f

Posted: Mon Aug 17, 2015 5:26 am
by Celauran
WordPress renders pages based off a series of templates in your theme's directory. You can take a look at the hierarchy on the WordPress site: https://developer.wordpress.org/themes/ ... hierarchy/

Re: PHP code to get a video URL and put it into video file f

Posted: Mon Aug 17, 2015 11:25 am
by steveryan
I've gone through the directory many times but I'm just not sure which template your talking about.

There's a lot of templates in there.

Re: PHP code to get a video URL and put it into video file f

Posted: Wed Aug 19, 2015 12:58 pm
by steveryan
Unfortunately, we are going to hire a developer to fix this for us. I thought for sure I could find a solution on my own, but I cant figure it out.

Thank you for your help though. We got close!