Home › Forums › Front-end Issues › 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.
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
You must be logged in to reply to this topic.
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.