Home › Forums › Front-end Issues › File field: Getting url on localhost but getting post-attachment-id on server
Hi! I’m using advanced custom fields pro and i have found an issue.
I’m getting post-attachment-id instead file url (acf file).
On my localhost, i’m using get_field(‘myfilefieldname’, $post->ID’) to retrieve an url from an uploaded video, it works. (ACF set to return url of a file)
When i upload to my test server, the same function give me the post-attachment-id.
I’m looping to create a video playlist inside a javascript tag, like this:
<script type="text/javascript">
<?php
switch_to_blog('3'); //switching to blog where the videos are hosted
$videos = get_posts(array(
'post_type'=> 'sec-videos', //selecting my post type
'posts_per_page'=> '5',
'meta_key'=> 'video_source', //testing for upload option for exact query
'meta_value'=>'1'
));
$playlist = array();
$ids = array();
foreach($videos as $video) { //for each video
$pid = $video->ID; //retrieve the ID (just for sure)
$videourl = get_field('video_upload', $pid); //try to get the acf 'video_upload'
array_push($playlist, "\"".$videourl."\""); //writing
array_push($ids, $pid);
echo "\n //titulo $video->post_title "; //testing for post values working
echo "\n //source ".get_field('video_source', $video->ID);//testing for post values working
echo "\n //url ".get_field('video_upload', $video->ID);//testing for post values NOT working
echo "\n";
}
wp_reset_postdata();
?>
var playlist = [<?php echo implode(",", $playlist); ?>];//prints my array of files
var ids = [<?php echo implode(",", $ids) ?>]; //printing array of post-ids
<?php restore_current_blog(); ?> //returning to my current_blog
</script>
Important information:
Using multisite, path based http://mysite.com/mynetworksite on localhost and webserver
Using normal (on wp-admin/database) acfs in localhost, testing $_server[http_host] and using exporting (php) for webserver
Same (something like > if webserver loads config-acf.php)
Php versions: 5.6 on localhost and webserver
Mysql versions: 5.0 on localhost, 5.5 on webserver
I’m getting other values trough this way.
I’ve tried to change the return value to array, and when i’ve did it, i’ve got an error on invalid index for the file object.
Please, help me.
Thank you!
Greetings from Brazil.
You field group that you export and include with PHP must be defined for the blog that you’re switching to. How are you creating the field group and is it created on all blogs? or at least the ones that need to use it.
Hi!
I’m creating the field groups via wp-admin, on acf front-end.
After, i’m exporting via exporting tool (from acf) and including on my functions.php.
I’m using a network for many sites (government), so i need my custom fields defined on my theme, i can’t use json import/export process every time i need an update, for each site.
The site where i’ve created my cfs is id 3, same on localhost and webserver.
I can retrieve a lot of data correctly, but in some cases, i’ve got post-attachment-id instead of my return option.
I’m in contact with the acf team to find the solution.
The topic ‘File field: Getting url on localhost but getting post-attachment-id on server’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.