Title: Loop trouble
Last modified: August 21, 2016

---

# Loop trouble

 *  [viktor89](https://wordpress.org/support/users/viktor89/)
 * (@viktor89)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/loop-trouble-2/)
 * I have some weird loop issue. Can’t really seem to figure out what goes wrong:/
   The pages load up fine on the website, but the first two “edit” buttons that 
   are put at the end of the page links to the first page.
 * My header opens with this:
 *     ```
       <?php $navquery = new WP_Query('post_type=page&meta_key=front_page&orderby=menu_order&order=ASC');; ?>
       			<?php while ( $navquery->have_posts() ) : $navquery->the_post(); ?>
       					<h2 id="nav_<?php the_title( ); ?>"><a href="<?php the_permalink(); ?>"><?php the_title( ); ?></a></h2>
       			<?php endwhile; // end of the loop. ?>
   
       			<h2 id="nav_kontaktos"><a onclick="nav_scroller('kontaktos');">Kontakt os</a></h2>
       			</div>
       		</nav><!-- #site-navigation -->
       		<?php } ?>
   
       		<?php $header_image = get_header_image();
       		if ( ! empty( $header_image ) ) : ?>
       			<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /></a>
       		<?php endif; ?>
       			</div>
       	</header><!-- #masthead -->
       <div id="page" class="hfeed site">
       	<div id="main" class="wrapper" style="background-image:url('<?php if(is_single()){echo get_template_directory_uri()."/img/blue.jpg" ;} ?>')">
       ```
   
 * Then my front-page templates makes:
 *     ```
       get_header(); ?>
   
       	<div id="primary" class="site-content">
   
       <?php $frontpagequery = new WP_query('post_type=page&meta_key=front_page&orderby=menu_order&order=ASC'); ?>
       	<?php while ( $frontpagequery->have_posts() ) : $frontpagequery->the_post(); ?>
       			<?php $field_choice = get_field('background'); ?>
   
       	<div id="content" class="background" style="<?php if(get_field('custom_color_background') == ""){echo "background-image:url('".get_template_directory_uri()."/img/".get_field('background').".jpg"."');";}else{background_colorer('custom_hex'); } ?>">
       		<div id="content" class="page">
       			<div class="page-inner-content" id="<?php echo strtolower(str_replace(' ', '', get_the_title())); ?>">
       				<div id="page-wrapper">
       	<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
   
       			<?php the_content(); ?>
       			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?>
   
       		<footer class="entry-meta">
       			<?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
       		</footer><!-- .entry-meta -->
       	</article><!-- #post -->
       </div>
   
       				<?php // comments_template( '', true ); ?>
       			</div>	
   
       		<div id="scroll_wrapper">
       			<p class="scroll_down_text">Scroll for at se mere!</p>
       			<img class="scroll_down" src="<?php echo get_template_directory_uri(); ?>/img/scroll.png">
       		</div>
   
       	</div><!-- #background -->
       		</div><!-- #content -->
       	<?php endwhile; // end of the loop. ?>
   
       	</div><!-- #primary -->
   
       <?php get_footer(); ?>
       ```
   
 * I have two loops in two of the pages loaded for the frontpage (shortcodes used
   in the content)
 * first is this one:
 *     ```
       <ul class="featured_posts">
       <?php
       $featured_courses_args = array( 'posts_type' => 'post', 'posts_per_page' => 4, 'category' => 3 );
   
       $featured_courses = get_posts( $featured_courses_args );
       foreach ( $featured_courses as $post ) : setup_postdata( $post ); ?>
   
       <li id="<?php echo strtolower(str_replace(' ', '', get_the_title())); ?>" class="featured_post"><?php
       	?><h2 class="featured_post_heading"><?php the_title(); ?></h2><?php
       	?><p class="featured_post_manchet"><?php echo(get_field('manchet')); ?></p><?php
       	?><p class="featured_post_body"><?php echo get_the_excerpt(); ?></p><?php
       	?><a class="featured_post_permalink" href="<?php the_permalink(); ?>">Read more</a><?php
       ?></li><?php
       endforeach; // end of the loop.
       wp_reset_query();
       ?>
       ```
   
 * the other is
 *     ```
       <?php
       /**
        * The template for displaying posts in the Quote post format
        *
        * @package WordPress
        * @subpackage Twenty_Twelve
        * @since Twenty Twelve 1.0
        */
       ?>
   
       <ul class="featured_posts">
       <?php
       $courses_args = array( 'post_type' => 'post', 'category' => 2 );
   
       $courses = get_posts( $courses_args );
       foreach ( $courses as $post ) : setup_postdata( $post ); ?>
   
       <li id="<?php echo strtolower(str_replace(' ', '', get_the_title())); ?>" class="featured_post"><?php
       	?><h2 class="featured_post_heading"><?php the_title(); ?></h2><?php
       	?><p class="featured_post_manchet"><?php echo(get_field('manchet')); ?></p><?php
       	?><p class="featured_post_body"><?php echo get_the_excerpt(); ?></p><?php
       	?><a class="featured_post_permalink" href="<?php the_permalink(); ?>">Read more</a>
       	</li><?php
       endforeach; // end of the loop.
       wp_reset_query();
       ?>
       ```
   
 * It’s probably a total mess, but could someone help me out?
 * Error can be viewed at [http://www.maigaardwww.dk](http://www.maigaardwww.dk)

The topic ‘Loop trouble’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [viktor89](https://wordpress.org/support/users/viktor89/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/loop-trouble-2/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
