简体   繁体   中英

wordpress the_field() path including array

Hey guys I'm new to wordpress development and the issue Im having is that the path returned for my files which I uploaded into a wordpress post using advanced custom fields seem to be outputting an array within the path. My code is below, please help if you can. I got an all nighter ahead of me so I'll be checkin in frequently.

this is the filepath I'm getting: 217, , des-desk-icon, , , image/png, http://localhost:8888/Wordpress%20development/wp-content/uploads/2016/08/des-desk-icon.png , 279, 279, Array

<?php while ( have_posts() ) : the_post(); ?>
                <h1><?php the_field('title'); ?></h1>
                <p><?php the_field('description'); ?></p>

                <?php if(get_field('column_description')): ?>
                    <div class="column_1">
                        <div class="column_1_image">
                        <img src="<?php the_field('column_1_image'); ?>"/>  
                        </div>
                        <div class="column_1_description">
                        <p><?php the_field('column_description'); ?></p>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if(get_field('column_2_description')): ?>
                    <div class="column_2">
                        <div class="column_2_image">
                            <img src="<?php the_field('column_2_image'); ?>"/>
                        </div>
                        <div class="column_2_description">
                            <p><?php the_field('column_2_description'); ?></p>
                        </div>
                    </div>
                <?php endif; ?>
            <?php endwhile;?>

Have a try of the code and it will work it .

ACF will return the image as array format and you have to use get_field() and print it using an array format.

<?php while ( have_posts() ) : the_post(); ?>
    <h1><?php the_field('title'); ?></h1>
    <p><?php the_field('description'); ?></p>

    <?php if(get_field('column_description')): ?>
        <div class="column_1">
            <div class="column_1_image">
            <?php
                $col1_image =get_field('column_1_image');
            ?>    
            <img src="<?php echo $col1_image['url']; ?>"/>  
            </div>
            <div class="column_1_description">
            <p><?php the_field('column_description'); ?></p>
            </div>
        </div>
    <?php endif; ?>
    <?php if(get_field('column_2_description')): ?>
        <div class="column_2">
            <div class="column_2_image">
                <?php
                $col2_image =get_field('column_2_image');
                ?> 
                <img src="<?php echo $col2_image['url']; ?>"/>
            </div>
            <div class="column_2_description">
                <p><?php the_field('column_2_description'); ?></p>
            </div>
        </div>
        <?php endif; ?>
<?php endwhile;?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM