Title: Code is causing wrong title to appear
Last modified: August 19, 2016

---

# Code is causing wrong title to appear

 *  Resolved [HorrorUK](https://wordpress.org/support/users/horroruk/)
 * (@horroruk)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/code-is-causing-wrong-title-to-appear/)
 * I’m having trouble getting the title to show up on my theme.
 * I’m using the following, which works ok on its own:
 *     ```
       <h1><?php the_title(); ?></h1>
       <div style="clear: both;"></div>
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <?php the_content(__('Keep Reading'));?>
       <?php endwhile; else: ?>
       <?php endif; ?>
       ```
   
 * I’ve got this code in a separate column:
 *     ```
       <?php $my_query = new WP_Query("showposts=2&cat=9&offset=0"); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       <?php the_excerpt(); ?><?php endwhile; ?>
       ```
   
 * I’ve narrowed down the problem to the following section of the above code:
 * `<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>`
 * But I can’t figure out why it’s a problem.
 * The following page is called ‘Video’, but it is showing the default WP page:
 * [http://ioaf.moonworks.co/video](http://ioaf.moonworks.co/video)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/code-is-causing-wrong-title-to-appear/#post-2041053)
 * Are you resetting the query between your two loops? i.e. are you calling:
 *     ```
       <?php wp_reset_query(); ?>
       ```
   
 * Also, in your custom query loop, does the following work?
 *     ```
       <?php echo $post->post_title; ?>
       ```
   
 * If so, then the problem is that you’re not setting up the $post data, which you
   would do by adding this:
 *     ```
       <?php setup_postdata(); ?>
       ```
   
 * This call would go somewhere here:
 *     ```
       <?php $my_query = new WP_Query("showposts=2&cat=9&offset=0"); ?>
       <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <?php setup_postdata(); ?>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <?php the_excerpt(); ?>
       <?php endwhile; ?>
       ```
   
 *  Thread Starter [HorrorUK](https://wordpress.org/support/users/horroruk/)
 * (@horroruk)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/code-is-causing-wrong-title-to-appear/#post-2041058)
 * Thank you Chip, once again, you have come to my rescue.
 * Adding the reset sorted out the problem.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Code is causing wrong title to appear’ is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [HorrorUK](https://wordpress.org/support/users/horroruk/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/code-is-causing-wrong-title-to-appear/#post-2041058)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
