Title: Operation on all custom posts
Last modified: August 31, 2016

---

# Operation on all custom posts

 *  Resolved [DimitrisL](https://wordpress.org/support/users/dimitrisl/)
 * (@dimitrisl)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/operation-on-all-custom-posts/)
 * I want to perform an operation to all posts of a certain post_type. However, 
   the query to get all posts of this type does not terminate when I set ‘numberposts’
   to -1. I would like to know if there is a way to understand what is causing this(
   memory or somekind of time) or an alternative way of performing an operation 
   to all posts.
 *     ```
       <?php
       /*
           Template Name: Update Maximum Threshold
       */
   
       $args = array( 'numberposts' => -1, 'post_type' => 'my_type');
       $posts= get_posts( $args );
       if ($posts) {
           foreach ( $posts as $post ) {
               setup_postdata($post);
               the_title(); // Just to check that it is updated
               // The operation
           }
       }
       ?>
       ```
   
 * Thanks in advance

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

 *  [Bob Cristello](https://wordpress.org/support/users/gntmidnight/)
 * (@gntmidnight)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/operation-on-all-custom-posts/#post-6953377)
 * This is probably a stupid question but did you set the numberposts to = a small
   number such as 5 to make sure that you were returning a set of records correctly?
 * My assumption, and I apologize for even making one, is that you are attempting
   to return all records and the memory is getting maxed out or you are exceeding
   your max timeout for php scripts. You can increase the max memory, if your host
   allows, using the wp-config.php file by adding this line:
 * define( ‘WP_MAX_MEMORY_LIMIT’, ‘256M’ );
 * There are others that you can add to control script timeout, etc. Please reference
   [https://codex.wordpress.org/Editing_wp-config.php](https://codex.wordpress.org/Editing_wp-config.php)
 * If your host does not allow this, you may have to contact them and see if they
   will re-configure your php.ini to reflect these values.
 *  Thread Starter [DimitrisL](https://wordpress.org/support/users/dimitrisl/)
 * (@dimitrisl)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/operation-on-all-custom-posts/#post-6953379)
 * Yes, it was displaying correctly for small numbers, but not for -1 (or values
   above 100). But, by changing the wp memory limit (and also the php memory limit)
   it works fine.
 * Thank you very much for your help.
 *  [swayam.tejwani](https://wordpress.org/support/users/swayamtejwani/)
 * (@swayamtejwani)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/operation-on-all-custom-posts/#post-6953391)
 * have you tried ‘posts_per_page’ ?

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

The topic ‘Operation on all custom posts’ is closed to new replies.

## Tags

 * [all posts](https://wordpress.org/support/topic-tag/all-posts/)
 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [swayam.tejwani](https://wordpress.org/support/users/swayamtejwani/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/operation-on-all-custom-posts/#post-6953391)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
