Title: $my_query-&gt;have_posts()) problems
Last modified: August 18, 2016

---

# $my_query->have_posts()) problems

 *  [webecho](https://wordpress.org/support/users/webecho/)
 * (@webecho)
 * [19 years ago](https://wordpress.org/support/topic/my_query-gthave_posts-problems/)
 * I have inserted the following code to my homepage
 *     ```
       <?php $my_query = new WP_Query('category_name=beauty-tips&showposts=2'); ?>
   
        <?php while ($my_query->have_posts()) : $my_query->the_post();?>
   
       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
   
         <?php endwhile; ?>
       ```
   
 * to try and get the latest 2 post in a certain category to show there.
 * At the moment the only thing that shows up is
 * have_posts()) : $temp_query->the_post();?>
 * For some reason it is displaying everything that is typed after `$my_query`
    
   I’m pretty new to PHP and WordPress and I can’t work out what could be wrong.
 * The code was copied directly from an article on this website
 * Thanks in advance
 * Webecho

The topic ‘$my_query->have_posts()) problems’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [webecho](https://wordpress.org/support/users/webecho/)
 * Last activity: [19 years ago](https://wordpress.org/support/topic/my_query-gthave_posts-problems/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
