Title: LOOP   função get_posts()
Last modified: August 19, 2016

---

# LOOP função get_posts()

 *  [buchacra](https://wordpress.org/support/users/buchacra/)
 * (@buchacra)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/loop-funcao-get_posts/)
 * Hello guys!
 * I have a loop on a page + function get_posts (). All this for the main loop runs,
   one more session outside the main loop that uses the get_posts ().
 * The problem is that the loop is operating normally. The get_posts () is not returning
   what was requested. See the code that is below:
 * //////////////////////////
 * <div class=”box”>
    <?php include(TEMPLATEPATH . ‘/includes/version.php’);
 * $the_query = new WP_Query(‘cat=-8,-9,-‘. $ex_feat . ‘,-‘ . $ex_vid . ‘&showposts
   =’ . $showposts . ‘&orderby=post_date&order=desc’);
 * $counter = 0; $counter2 = 0;
 * while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate 
   = $post->ID;
    ?> <?php $counter++; $counter2++; ?> <div class=”post <?php if (
   $counter == 1) { echo ‘fl’; } else { echo ‘fr’; $counter = 0; } ?>”> <h3 class
   =”posted”>+ <?php the_category(‘, ‘) ?> </h3> <?php if ( get_post_meta($post-
   >ID, ‘thumb’, true) ) { ?> <!– DISPLAYS THE IMAGE URL SPECIFIED IN THE CUSTOM
   FIELD –> <img src=”<?php echo get_post_meta($post->ID, “thumb”, $single = true);?
   >” alt=”” /> <?php } else { ?> <!– DISPLAY THE DEFAULT IMAGE, IF CUSTOM FIELD
   HAS NOT BEEN COMPLETED –> <!–<img src=”<?php //bloginfo(‘template_directory’);?
   >/images/no-img-thumb.jpg” alt=”” />–> <?php } ?> <h2>” href=”<?php the_permalink()?
   >” rel=”bookmark”> <?php the_title(); ?> </h2> <p><?php echo strip_tags(get_the_excerpt(),”);?
   ></p> <p><span class=”continue”>” href=”<?php the_permalink() ?>”>Continue…</
   span> | <span class=”comments”> <?php comments_popup_link(‘Depoimentos (0)’, ‘
   Depoimentos (1)’, ‘Depoimentos (%)’); ?> </span></p> </div> <!–/post–> <?php 
   if ( !($counter2 == $showposts) && ($counter == 0) ) { echo ‘<div class=”hl-full”
   ></div>’; ?> <?php } ?> <?php endwhile;
 * wp_reset_query();
 * ?>
    </div> <!–/box–> <div id=”topbanner”> <?php
 * // Get banner code //
    $banner_img = get_option(‘premiumnews_banner_image’); 
   $banner_url = get_option(‘premiumnews_banner_url’);
 * ?>
    href=”<?php echo “$banner_url”; ?>”><img src=”<?php echo “$banner_img”; ?
   >” alt=”” /> </div> <div class=”boxes”> <h3 class=”posted”> VEJA TAMBEM</h3>
 * <?php
    // enter the IDs of the categories to display $display_categories = array(
   3,6); foreach ($display_categories as $category): setup_postdata($post); { ?>
   <div class=”col4″> <?php query_posts(“showposts=1&include=$category”);?> <?php
   if ( get_post_meta($post->ID, ‘thumb-h’, true) ) { ?> <!– DISPLAYS THE IMAGE 
   URL SPECIFIED IN THE CUSTOM FIELD –> <img src=”<?php echo get_post_meta($post-
   >ID, “thumb-h”, $single = true); ?>” alt=”” /> <?php } ?> <h2>” href=”<?php the_permalink()?
   >” rel=”bookmark”> <?php the_title(); ?> </h2> <p><?php echo strip_tags(get_the_excerpt(),”);?
   ></p> <p><span class=”continue”>” href=”<?php the_permalink() ?>”>Continue…</
   span> | <span class=”comments”> <?php comments_popup_link(‘Depoimentos (0)’, ‘
   Depoimentos (1)’, ‘Depoimentos (%)’); ?> </span></p> </div> <?php } endforeach;
   wp_reset_query(); ?> <!– LAST CATEGORY LISTING – NEEDED TO END CSS COLUMNS –>
   <div class=”col5″> <?php query_posts(“showposts=1&include=35”); ?> <?php if (
   get_post_meta($post->ID, ‘thumb-h’, true) ) { ?> <!– DISPLAYS THE IMAGE URL SPECIFIED
   IN THE CUSTOM FIELD –> <img src=”<?php echo get_post_meta($post->ID, “thumb-h”,
   $single = true); ?>” alt=”” /> <?php } ?> <h2>” href=”<?php the_permalink() ?
   >” rel=”bookmark”> <?php the_title(); ?> </h2> <p><?php echo strip_tags(get_the_excerpt(),”);?
   ></p> <p><span class=”continue”>” href=”<?php the_permalink() ?>”>Continue…</
   span> | <span class=”comments”> <?php comments_popup_link(‘Depoimentos (0)’, ‘
   Depoimentos (1)’, ‘Depoimentos (%)’); ?> </span></p> </div> <hr> </hr> </div>
 * /////////////////
 * Can anyone help me?

The topic ‘LOOP função get_posts()’ is closed to new replies.

## Tags

 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [buchacra](https://wordpress.org/support/users/buchacra/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/loop-funcao-get_posts/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
