Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Konrad Pilch
Konrad Pilch
2,435 Points

get_field('not_working');

After my portfolio code, anything udner related to wp breaks

HI

So after this code

        <div class="row">                   


            <?php 
              $temp = $wp_query; 
              $wp_query = null; 
              $wp_query = new WP_Query(); 
              $wp_query->query('showposts=6&post_type=portfolio'.'&paged='.$paged); 
            ?> 


            <?php  while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

            <div class="col-md-4 col-sm-6 portfolio-item">
              <a href="<?php echo get_field('portfolio_site_url'); ?> " target="_blank" class="portfolio-link" data-toggle="modal">
                <div class="portfolio-hover">
                    <div class="portfolio-hover-content">
                        <i class="fa fa-plus fa-3x"></i>
                    </div>
                </div>
                 <img style="background-image:url(<?php echo get_field('portfolio_image_post'); ?>);">
              </a>

              <div class="portfolio-caption">
                <h4><a href="<?php echo get_field('portfolio_site_url'); ?>" target="_blank"><?php the_title(); ?></a></h4>
                <p class="text-muted"></p>
              </div>
            </div><!-- col-* -->


            <?php endwhile;?>

            <?php 
                 $wp_query = null; 
                 $wp_query = $temp;  // Reset
            ?>

        </div><!-- /row -->
    </div><!-- /container -->
</div>

Mainly this:

 <?php 
              $temp = $wp_query; 
              $wp_query = null; 
              $wp_query = new WP_Query(); 
              $wp_query->query('showposts=6&post_type=portfolio'.'&paged='.$paged); 
            ?> 

It breaks my :

<!-- Quote -->
<div class="quote section-padding" style="background-image: url(<?php echo get_field('quote_image_background'); ?>);">
    <div class="container"> 
        <div class="row">
            <div class="col-lg-12">
              <h3><?php echo get_field('quote_title'); ?></h3>
                <h4><?php echo get_field('quote_author'); ?></h4>
            </div><!-- /col-lg-12 -->
        </div><!-- /row -->
    </div><!-- /container -->
</div><!-- /quote -->

And wont show me fields that im echo out. How come?

This code works perfeclty on my portfolio page. Reference this Markdown Cheatsheet for syntax examples for formatting your post.

1 Answer

Konrad Pilch
Konrad Pilch
2,435 Points

After 24hours, from some Zac video, i remembered that he said to close the WP Queries because it can cause some problems, yay.

Solution re-solverd

<?php wp_reset_query(); ?>

<3