Title: Optimize this Php call?
Last modified: August 19, 2016

---

# Optimize this Php call?

 *  [Virendar](https://wordpress.org/support/users/virendar/)
 * (@virendar)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/optimize-this-php-call/)
 * I got a little code that calls all the posts in the category of the currently
   viewing post
 * it is as followes
 *     ```
       <ul>
       <?php
       foreach( ( get_the_category() ) as $category ) {
       $the_query = new WP_Query('category_name=' . $category->category_nicename . '&showposts=-1');
       while ($the_query->have_posts()) : $the_query->the_post();
       ?>
       			<li>
       				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a>
       			</li>
       <?php endwhile; ?>
       <?php
       }
       ?>
       </ul>
       ```
   
 * some categories have 500+ posts, and this is a very slow query
 * anyway to make it more efficient? or at least make it load last or separately
   so it does not affect the overall loading time of a page?

The topic ‘Optimize this Php call?’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [Virendar](https://wordpress.org/support/users/virendar/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/optimize-this-php-call/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
