Support

Account

Home Forums Front-end Issues Nothing showing up in the page!

Solved

Nothing showing up in the page!

  • Im having trouble getting any info to show on the page that is served.
    Here is the code, its a mess because of me trying several things

    <?php
    /*
        Template Name: Sponsors
    */
    
    get_header();
    
    $sponsor_image = get_field('sponsor_image');
    $sponsor_url = get_field('sponsor_url');
    ?>
    
    <?php $loop = new WP_Query( array( 'post_type' => 'sponsor', 'orderby' => 'post_id', 'order' => 'ASC') )?>
    
    <div id="hero" class="sponsor-row clearfix">
        <?php while( $loop->have_posts() ) : $loop->the_post(); ?>
    
            <div>
    <!--            Sponsor Image test 1-->
                    <img src="<?php echo $sponsor_image["url"]; ?>" alt="<?php echo $sponsor_image["alt"]; ?>" />
                <!--            Sponsor Image test 2-->
                    <img src="<?php the_field("sponsor_image['url']"); ?>" alt="" />
                <!--            Sponsor Image test 3-->
                    <img src="<?php echo $sponsor_image['url']; ?>" alt="<?php echo $sponsor_image['alt']; ?>" />
                <!--            Sponsor Image test 4-->
                    <img src="<?php the_field("sponsor_image"); ?>" alt="" />
                <!--            Sponsor Image test 5-->
                    <img src="<?php the_field('sponsor_image'); ?>" alt="" />
    
    <!--            End Sponsor Image-->
                <?php the_content();?>
                <!--            Sponsor url-->
                <a href="<?php echo $sponsor_url; ?>">LOLO</a>
    
                <!--            End Sponsor url-->
            </div>
    
        <?php endwhile; ?>
        <?php
        echo '<pre>';
    	var_dump( $sponsor_image );
    echo '</pre>';
        ?>
    
    </div>
    
    <?php get_footer(); ?>
    

    And here is the view-source from the web browser

    <div id="hero" class="sponsor-row clearfix">
        
            <div>
    <!--            Sponsor Image test 1-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 2-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 3-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 4-->
                    <img src="46, , DX Engineering Logo, , , image/png, http://localhost/wp-content/uploads/2016/02/dxelogo.png, 117, 66, Array" alt="" />
                <!--            Sponsor Image test 5-->
                    <img src="46, , DX Engineering Logo, , , image/png, http://localhost/wp-content/uploads/2016/02/dxelogo.png, 117, 66, Array" alt="" />
    
    <!--            End Sponsor Image-->
                <p>Bla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de BlaBla de a</p>
                <!--            Sponsor url-->
                <a href="">LOLO</a>
    
                <!--            End Sponsor url-->
            </div>
    
        
            <div>
    <!--            Sponsor Image test 1-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 2-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 3-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 4-->
                    <img src="44, HamShirts Logo, HamShirts Logo, , , image/png, http://localhost/wp-content/uploads/2016/02/hamshirtslogo-1.png, 675, 65, Array" alt="" />
                <!--            Sponsor Image test 5-->
                    <img src="44, HamShirts Logo, HamShirts Logo, , , image/png, http://localhost/wp-content/uploads/2016/02/hamshirtslogo-1.png, 675, 65, Array" alt="" />
    
    <!--            End Sponsor Image-->
                <p>dfgdfgdfgdfgdfg</p>
                <!--            Sponsor url-->
                <a href="">LOLO</a>
    
                <!--            End Sponsor url-->
            </div>
    
        
            <div>
    <!--            Sponsor Image test 1-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 2-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 3-->
                    <img src="" alt="" />
                <!--            Sponsor Image test 4-->
                    <img src="52, KD7MAZ, KD7MAZ, , , image/png, http://localhost/wp-content/uploads/2016/02/img0060.png, 279, 113, Array" alt="" />
                <!--            Sponsor Image test 5-->
                    <img src="52, KD7MAZ, KD7MAZ, , , image/png, http://localhost/wp-content/uploads/2016/02/img0060.png, 279, 113, Array" alt="" />
    
    <!--            End Sponsor Image-->
                <p>uioyuioyuioyu</p>
                <!--            Sponsor url-->
                <a href="">LOLO</a>
    
                <!--            End Sponsor url-->
            </div>
    
            <pre>bool(false)
    </pre>
    </div>
    

    As you can see I do get any info from the content box but not the proper info if any at all is showing up from ACF,

    As you see I do get something from the back end in comments Sponsor Image test 4 and Sponsor Image test 5 but it is not formated to show the right info.

    Any comments or help will be greatly appreciated.

  • Hi @theolddisabledguy

    The issue occurred because you tried to get the field outside The Loop. If you want to get it outside the loop, you need to provide the post ID. This page should give you more idea about it: http://www.advancedcustomfields.com/resources/get_field/.

    Please try this code instead:

    <?php $loop = new WP_Query( array( 'post_type' => 'sponsor', 'orderby' => 'post_id', 'order' => 'ASC') ); ?>
    
    <div id="hero" class="sponsor-row clearfix">
        <?php while( $loop->have_posts() ) : $loop->the_post();
            $sponsor_image = get_field('sponsor_image');
            $sponsor_url = get_field('sponsor_url');
        ?>
    
            <div>
                <img src="<?php echo $sponsor_image["url"]; ?>" alt="<?php echo $sponsor_image["alt"]; ?>" />
                <a href="<?php echo $sponsor_url; ?>">LOLO</a>
            </div>
            <pre>
                <?php var_dump( $sponsor_image ); ?>
            </pre>
    
        <?php endwhile; ?>
    
    </div>
    <?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>

    I hope this helps.

  • Thanks, I was just following the video and as I see it was WRONG! You have been a big help

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

The topic ‘Nothing showing up in the page!’ is closed to new replies.