Support

Account

Home Forums Front-end Issues image url broken after migration

Solved

image url broken after migration

  • I am using an “Image” field type for my custom post type with a Return Format of “image URL”.
    It is working fine and showing on the front end before migration.
    Here is my code:

    <?php if( have_posts() ): ?>
    	<?php while( have_posts() ): the_post(); ?>
    		<div class="work-image">
    			<img src="<?php the_field('wk_img'); ?>" class="img-responsive"/>
    		</div>
    	<?php endwhile; ?>
    <?php endif; wp_reset_query(); ?>

    Then after migration, On the frontend the image URL is broken and looks like this:
    <img src="164" class="img-responsive">
    But on the backend, the image is showing correctly on the custom post type.

    Did someone also encounter this? Please respond if you have or if you have any idea why is this happening. Thanks

  • That looks like it is returning the image post ID or the post ID instead of the URL.

    Try debugging and seeing what this returns:

    $image_url = get_field('wk_img');

    I would also check if something is modifying the main query.

  • The problem is that the ACF field key reference is missing in the DB, or the field key reference is wrong. How did you migrate the site?

    Every field has 2 entries in the meta table

    
    meta_key       | meta_value
    {$field_name}  | value
    _{$field_name} | acf field key
    

    without the second entry ACF does not know what to do with the value in the first entry

  • The other issue that could be happening is that the ID of the image has changed from one site to the other. If you used a standard export/import to move things then the post IDs on the new site will not match the post IDs on the old site. When moving a site you must ensure that all posts maintain the same IDs and this cannot be don by exporting and importing, you’ve basically got to copy the DB as is.

    Again, this comes down to how the site was migrated.

  • Ok thank you both. I don’t remember which plugin did I use (duplicator or All-In-One Wp migration). I just re-saved the posts one by one to resolve the issue immediately.

    So from now on i will migrate manually if I have Acf installed.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘image url broken after migration’ is closed to new replies.