logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
Moving website - custom postmeta uploaded files not showing

I built a client's website on my dev server, moved it to their hosting account today and the images uploaded through the custom meta fields I created in their theme are no longer showing. No URL is returned in the image src

- I ran an SQL query to replace the filepaths and URLs in the database, and the filepaths and URLs are correct in the database
- File permissions are the same - the hosting account is on the same host
- Images attached to posts display fine

Any thoughts?!

This question has been answered.

Dan Davies | 05/13/12 at 10:57am Edit


(5) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    05/13/12
    11:00am
    John Cotton says:

    Presumably you've copied the images over?

    Do the URLs in the meta fields correctly display the images when used directly in a browser?

    • 05/13/12 11:05am

      Dan Davies says:

      Yep, images copied over

      If I take the URL from the table row then I and load it in my browser then the image loads - so the paths and URLs are definitely correct.

      The website isn't live currently, I've just modified my hosts file, but I can't see that being an issue considering the images load directly.

    • 05/13/12 11:07am

      John Cotton says:

      The website isn't live currently, I've just modified my hosts file, but I can't see that being an issue considering the images load directly.

      That seems fair enough.

      What about the HTML output - how wrong is it? ie is the img element there without a src, or is the img element missing?

      Perhaps if you put up some of the code around where things go wrong we could spot something...

    • 05/13/12 11:09am

      Dan Davies says:

      There's literally no src being output on any of the custom meta images

      <img class="active" src="" width="91" height="72" />


      All of the standard images inserted into a post through the WordPress media uploader are displaying fine inside the content.

    • 05/13/12 11:14am

      John Cotton says:

      Can you post the code from the point it retrieves the meta value to the output so that I can see what's happening?

    • 05/13/12 11:18am

      Dan Davies says:

      Here's the code in the template


      <?php $logos = new WP_Query('post_type=projects&showposts=9&meta_key=bs_feature_clients&meta_value=on'); ?>
      <?php if($logos->have_posts()) : ?><?php $counter = 1; while($logos->have_posts()) : $logos->the_post(); ?>
      <?php $alogo = get_post_meta($post->ID, 'bs_project_logo', true); ?>
      <?php $hlogo = get_post_meta($post->ID, 'bs_project_logo_hover', true); ?>
      <?php $class = ''; ?>
      <?php if($counter %3) { $class = ''; } else { $class = 'third'; } ?>
      <div class="logo <?= $class; ?>">
      <a href="<?php the_permalink(); ?>"><img class="active" src="<?php echo $alogo['url']; ?>" width="91" height="72" /></a>
      <a href="<?php the_permalink(); ?>"><img class="hover" src="<?php echo $hlogo['url']; ?>" width="91" height="72" /></a>
      </div>

      <?php $counter++; endwhile; endif; ?>


      Here's the output:


      <div class="logo ">
      <a href="http://www.brightsparkcreative.com/projects/pye/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/pye/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo ">
      <a href="http://www.brightsparkcreative.com/projects/robe/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/robe/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo third">
      <a href="http://www.brightsparkcreative.com/projects/pro-health-store/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/pro-health-store/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo ">
      <a href="http://www.brightsparkcreative.com/projects/pageant-media/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/pageant-media/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo ">
      <a href="http://www.brightsparkcreative.com/projects/zafferano/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/zafferano/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo third">
      <a href="http://www.brightsparkcreative.com/projects/haultastic/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/haultastic/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo ">
      <a href="http://www.brightsparkcreative.com/projects/jo-behari/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/jo-behari/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo ">
      <a href="http://www.brightsparkcreative.com/projects/the-goodlife-centre/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/the-goodlife-centre/"><img class="hover" src="" width="91" height="72" /></a>
      </div>

      <div class="logo third">
      <a href="http://www.brightsparkcreative.com/projects/mind/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/mind/"><img class="hover" src="" width="91" height="72" /></a>
      </div>


      Exact same code as on the dev server, only there the images display!

    • 05/13/12 11:29am

      John Cotton says:

      Just after this line:

      <?php $alogo = get_post_meta...


      Can you add this and tell me what you get?

      <?php print_r($alogo); ?>

    • 05/13/12 11:32am

      Dan Davies says:

      Nothing's different

    • 05/13/12 11:36am

      John Cotton says:

      Nothing's different

      I assume you mean nothing is shown?

      And that explains why no src is output - the meta data is empty.

      You said that the values looked correct in the database.

      Have you checked that the post_id value in the post_meta table is the same as the id in the wp_post table (or the id in the url when you are editing that post?).

      That's the next step.

    • 05/13/12 11:41am

      Dan Davies says:

      Sorry, yes, nothing is shown.

      So looking at the first post that is output by that query:


      <div class="logo ">
      <a href="http://www.brightsparkcreative.com/projects/pye/"><img class="active" src="" width="91" height="72" /></a>
      <a href="http://www.brightsparkcreative.com/projects/pye/"><img class="hover" src="" width="91" height="72" /></a>
      </div>


      That is post ID 162.

      The postmeta row for 'bs_project_logo' on post ID 162 is

      a:3:{s:4:"file";s:129:"/home/brightsp/public_html/wp-content/uploads/2012/05/PYE-logo-grey1.jpg";s:3:"url";s:92:"http://www.brightsparkcreative.com/wp-content/uploads/2012/05/PYE-logo-grey1.jpg";s:5:"error";s:0:"";}


      The filepath and URL for that file are correct

    • 05/13/12 11:54am

      John Cotton says:

      Try adding

      global $post;


      just before the code you posted.

    • 05/13/12 11:57am

      Dan Davies says:

      Have done - still no image srcs.

      Besides, the code is identical on the dev site

    • 05/13/12 12:58pm

      John Cotton says:

      I reuploaded one of the files and that file now displays fine - I'd just rather avoid reuploading 100+ files if I can ;)


      Since that works you need to compare the before and after values of the postmeta table to see if there's a difference.

      Note the state of one post, upload the files again for that post and then compare.

      If they are identical, there must be some external value that's changing, either in another table or cached somewhere. I don't know the theme so can't comment what it might be, but that would be where to look.

    • 05/13/12 1:30pm

      Dan Davies says:

      Here's a field that hasn't been updated

      a:3:{s:4:"file";s:129:"/home/brightsp/public_html/wp-content/uploads/2012/05/PYE-logo-grey1.jpg";s:3:"url";s:92:"http://www.brightsparkcreative.com/wp-content/uploads/2012/05/PYE-logo-grey1.jpg";s:5:"error";s:0:"";}


      And here's one that has

      a:3:{s:4:"file";s:75:"/home/brightsp/public_html/wp-content/uploads/2012/05/PYE-logo-colour11.jpg";s:3:"url";s:83:"http://www.brightsparkcreative.com/wp-content/uploads/2012/05/PYE-logo-colour11.jpg";s:5:"error";s:0:"";}


      I'm not sure what the numbers mean, but otherwise I don't see a difference.

      Interestingly in the database now, there are multiple instances of the same meta_key for that post_id with different meta_ids. I'm not sure if when WordPress saves a post it updates the existing meta_key, or adds a new one with a new meta_id, but I now have multiple instances of bs_project_logo for post_id 162.

    • 05/13/12 2:30pm

      John Cotton says:

      OK - I think I know what you're problem is.

      The numbers in the serialized array are the character lengths of the string.

      Clearly, your dev urls are much longer (or at least of a different length) than your production ones.

      When PHP tries to deserialize the array from the database, the numbers are wrong because you've updated the urls/paths.

      Thus PHP gives you a null value (since it can't do anything with the corrupt data).


      What to do about it?

      Rather than doing a search and replace in the database, you've got to write a little routine that pulls all the meta values out (ie deseriliazes) replace the urls/paths and then reserialize back into the database.

      Pseudo code would be:


      $results = $wpdb->get_results("SELECT * FROM wp_postmeta WHERE meta_key = 'bs_project_logo''');

      foreach( $results as $result ) {
      $result['url'] = str_replace( OLD_URL, NEW_URL $result['url']);
      $wpdb->query("UPDATE.....");
      }

    • 05/13/12 2:59pm

      Dan Davies says:

      Running into a minefield of objects and arrays now. I expect your solution will work, but given my lack of PHP knowledge it may be quicker to reupload the files!

  • avatar
    Last edited:
    05/13/12
    11:18am
    idt says:

    Please post the code used to display the images.

    Thanks,
    idt

    • 05/13/12 11:24am

      Dan Davies says:

      See above :)

    • 05/13/12 11:35am

      idt says:

      What happens if you change <?php echo $alogo['url']; ?> and <?php echo $hlogo['url']; ?> to just <?php echo $alogo; ?> and <?php echo $hlogo; ?>

    • 05/13/12 11:38am

      idt says:

      Also, please try adding: global $post; above your code.

    • 05/13/12 11:44am

      Dan Davies says:

      Nothing is output

    • 05/13/12 12:01pm

      idt says:

      You already have

      global $post;
      in your code, right?

    • 05/13/12 12:06pm

      Dan Davies says:

      Yes. Given the code is working on the dev site, that shouldn't be an issue.

    • 05/13/12 12:12pm

      idt says:

      Did you happen to copy the database from one server to another? I think this is the same issue as you're experiencing right now: http://stackoverflow.com/questions/9101323/wordpress-loses-ability-to-read-and-store-custom-metabox-data-when-database-is-c

    • 05/13/12 12:14pm

      idt says:

      As per that link:

      I've "fixed" this by deleting the serialized data from the database manually. I was then able to enter it all back in again by hand...

    • 05/13/12 12:18pm

      Dan Davies says:

      Thanks for the link :) Hopefully I won't have to go through and remove & replace all of the meta field values, but it's an option.

      Curiously, unlike that poster, it's only the file upload meta that isn't working. All of the standard text fields are returning their data just fine.

    • 05/13/12 12:22pm

      idt says:

      It seems though that your issue is the same as that one on the link. Your code seems fine as per replies here so it should have worked. Please test what was suggested there, try changing the value of one entry and let's see how it goes. Thanks.

    • 05/13/12 12:50pm

      idt says:

      Also the same as this:

      So try re-saving or editing one the entries.

    • 05/13/12 12:52pm

      idt says:

      Oops... link gone: http://wordpress.org/support/topic/custom-post-type-and-custom-meta-box-issues

    • 05/13/12 12:52pm

      Dan Davies says:

      Yeah, I tried re-saving, no change.

      I reuploaded one of the files and that file now displays fine - I'd just rather avoid reuploading 100+ files if I can ;)

    • 05/13/12 1:03pm

      idt says:

      Out of curiosity, what happens when you remove

      , true
      from

      get_post_meta($post->ID, 'bs_project_logo', true)

      get_post_meta($post->ID, 'bs_project_logo_hover', true)
      and used $alogo['url']; and $hlogo['url']; in your code?

    • 05/13/12 1:31pm

      Dan Davies says:

      That makes no difference

    • 05/13/12 1:34pm

      Dan Davies says:

      Sorry, it does make a difference. If I remove the ', true' then the one image that was displaying no longer displays.

  • avatar
    Last edited:
    05/13/12
    11:18am
    Jatin Soni says:

    Check your permalink structure with the localhost site..

    • 05/13/12 11:24am

      Dan Davies says:

      Permalinks are default on the dev site, /%category%/%postname%/ on the 'live' site. Switched them to default on the 'live' site and the images still didn't display.

    • 05/13/12 11:25am

      Jatin Soni says:

      Have you use absolute url for custom post meta images?

    • 05/13/12 11:26am

      Dan Davies says:

      Sorry, not sure I understand your question

    • 05/13/12 11:43am

      Jatin Soni says:

      Can you please check and confirm that for further investigation.

  • avatar
    Last edited:
    05/13/12
    11:34am
    Just Me says:

    When you edit the post, is the link to the logo present?
    It seems the connection between post and logo got lost?

    • 05/13/12 11:35am

      Dan Davies says:

      Alas I've not returned the current image set for a custom meta field in the post editor, so couldn't tell you.

    • 05/13/12 12:43pm

      Just Me says:

      Did you check if there is a mix up with lower- and uppercase characters? In your image url.

  • avatar
    Last edited:
    05/13/12
    11:37am
    Christianto says:

    Hi,

    Could you check if by echoing $post->ID, the correct value appear?
    Or you can replace $post->ID with get_the_ID()

    Let me know if this not works..

    • 05/13/12 11:43am

      Dan Davies says:

      Yep, that returns the correct post IDs

    • 05/13/12 12:28pm

      Christianto says:

      If with get_post_meta() with correct ID doesn't work, what if we throw all meta value?

      print_r(get_post_custom($post->ID));

      Can you see your meta value?

    • 05/13/12 12:31pm

      Dan Davies says:

      Yep - all of the postmeta attached to each post is returned correctly.

    • 05/13/12 12:42pm

      Christianto says:

      If the meta bs_project_logo & bs_project_logo_hover url value exists,
      then you can use it for temporary :)

      you could try to re-save the post and all custom field to see if it appear by using get_post_meta();
      maybe the problem comes from wp_cache_get() that used inside get_post_meta/get_metadata function.

    • 05/13/12 1:26pm

      Christianto says:

      If you want to use get_post_custom() instead of get_post_meta(), you can try this..

      <?php $logos = new WP_Query('post_type=projects&showposts=9&meta_key=bs_feature_clients&meta_value=on'); ?>
      <?php if($logos->have_posts()) : ?><?php $counter = 1; while($logos->have_posts()) : $logos->the_post(); ?>
      <?php $all_meta_data = get_post_custom($post->ID);
      <?php $alogo = unserialize($all_meta_data['bs_project_logo'][0]); ?>
      <?php $hlogo = unserialize($all_meta_data['bs_project_logo_hover'][0]); ?>
      <?php $class = ''; ?>
      <?php if($counter %3) { $class = ''; } else { $class = 'third'; } ?>
      <div class="logo <?= $class; ?>">
      <a href="<?php the_permalink(); ?>"><img class="active" src="<?php echo $alogo['url']; ?>" width="91" height="72" /></a>
      <a href="<?php the_permalink(); ?>"><img class="hover" src="<?php echo $hlogo['url']; ?>" width="91" height="72" /></a>
      </div>
      <?php $counter++; endwhile; endif; ?>


      hope this help..

    • 05/13/12 1:31pm

      Christianto says:

      Duh.. I forgot the closing php tag..
      try code below..

      <?php $logos = new WP_Query('post_type=projects&showposts=9&meta_key=bs_feature_clients&meta_value=on'); ?>
      <?php if($logos->have_posts()) : ?><?php $counter = 1; while($logos->have_posts()) : $logos->the_post(); ?>
      <?php $all_meta_data = get_post_custom($post->ID); ?>
      <?php $alogo = unserialize($all_meta_data['bs_project_logo'][0]); ?>
      <?php $hlogo = unserialize($all_meta_data['bs_project_logo_hover'][0]); ?>
      <?php $class = ''; ?>
      <?php if($counter %3) { $class = ''; } else { $class = 'third'; } ?>
      <div class="logo <?= $class; ?>">
      <a href="<?php the_permalink(); ?>"><img class="active" src="<?php echo $alogo['url']; ?>" width="91" height="72" /></a>
      <a href="<?php the_permalink(); ?>"><img class="hover" src="<?php echo $hlogo['url']; ?>" width="91" height="72" /></a>
      </div>
      <?php $counter++; endwhile; endif; ?>


      sorry its late night here.. :)

    • 05/13/12 1:33pm

      Dan Davies says:

      I just switched to that code, and the images aren't being displayed (except the one I uploaded to test if re-uploading files would work)

This question has expired.



Dan Davies, Gabriel Reguly, Hai Bui, Francisco Javier Carazo Gil voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.