Title: Warning: array_shift() expects parameter 1 to be array error in WP post loop
Last modified: August 20, 2016

---

# Warning: array_shift() expects parameter 1 to be array error in WP post loop

 *  Resolved [Murtaza Frosh](https://wordpress.org/support/users/maimooninc/)
 * (@maimooninc)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/warning-array_shift-expects-parameter-1-to-be-array-error-in-wp-post-loop/)
 * I get
 * Warning: array_shift() expects parameter 1 to be array, boolean given in C:\wamp\
   www\Dropbox\ktechwp\wp-content\themes\ktech\single-shredders.php on line 118
 * for a loop that goes to the taxonomy ‘shredder-usage’ under custom post type ‘
   shredders’ and shows all the post under that taxonomy term. The following code
   works in the single-safes.php
 *     ```
       <div id="othrsizes"><h2>Other Products</h2>
   
       <?php
   
       $sectors = get_the_terms( get_the_ID(), 'safe-type' );
   
       if ( ! is_wp_error( $sectors ) ) {
   
       	$term = array_shift( $sectors );
   
       	/* Query for jobs that are in the sector. */
   
       	$jobs = null;
   
       	if ( isset( $term->slug ) && isset( $term->taxonomy ) ) {
   
       		$jobs = get_posts( array(
   
       			'term'        => $term->slug,
   
       			'taxonomy'    => $term->taxonomy,
   
       			'post_type'   => 'safes',
   
       			'post_status' => 'publish',
   
       			) );
   
       	}
   
       	/* Loop over all jobs and display an unordered list. */
   
       	if ( $jobs ) {
   
       		$_post = $post;
   
       		print '<ul>';
   
       		foreach ( (array) $jobs as $post ) {
   
       			setup_postdata( $post );
       			echo '<div class="productimg"><a href="' . esc_url( get_permalink() ) . '">';
       			the_post_thumbnail();
       			the_title( '<li><a href="' . esc_url( get_permalink() ) . '">', '</a></li>' );
   
       			if(get_field('new_price'))
       			{
       				echo '<span class="old_price">Rs. ' .get_field('price') . '</span> > <span class="price">Rs. ' . get_field('new_price') . '</span>';
       			}
       			else
       			{
       				echo '<span class="price">Rs. ' . get_field('price') . '</span>';
       			}
   
       			echo "</a></div>";
   
       		}
   
       		print '</ul>';
   
       		$post = $_post;
   
       	}
   
       }
   
       ?>
   
           </div>
       ```
   
 * but the following code which is the same after I change the taxanomy name ‘safes’
   top ‘shredder-usage’ and post type ‘safes’ to ‘shredders’ does not work and gives
   me warning mentioned above.
 *     ```
       <div id="othrsizes"><h2>Other Products</h2>
   
       <?php
   
       $sectors = get_the_terms( get_the_ID(), 'shredder-usage' );
   
       if ( ! is_wp_error( $sectors ) ) {
   
       	$term = array_shift( $sectors );
   
       	/* Query for jobs that are in the sector. */
   
       	$jobs = null;
   
       	if ( isset( $term->slug ) && isset( $term->taxonomy ) ) {
   
       		$jobs = get_posts( array(
   
       			'term'        => $term->slug,
   
       			'taxonomy'    => $term->taxonomy,
   
       			'post_type'   => 'shredders',
   
       			'post_status' => 'publish',
   
       			) );
   
       	}
   
       	/* Loop over all jobs and display an unordered list. */
   
       	if ( $jobs ) {
   
       		$_post = $post;
   
       		print '<ul>';
   
       		foreach ( (array) $jobs as $post ) {
   
       			setup_postdata( $post );
       			echo '<div class="productimg"><a href="' . esc_url( get_permalink() ) . '">';
       			the_post_thumbnail();
       			the_title( '<li><a href="' . esc_url( get_permalink() ) . '">', '</a></li>' );
   
       			echo "</a></div>";
   
       		}
   
       		print '</ul>';
   
       		$post = $_post;
   
       	}
   
       }
   
       ?>
   
           </div>
       ```
   
 * Please review and help

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

 *  [popper](https://wordpress.org/support/users/julialasarte/)
 * (@julialasarte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/warning-array_shift-expects-parameter-1-to-be-array-error-in-wp-post-loop/#post-2864464)
 * `get_the_terms` will return `false` if no terms are found in the given taxonomy.
   WordPress is not finding any terms in ‘shredder-usage’, returning `false` and
   causing that error, since you are passing a boolean to `array_shift`.
 *  Thread Starter [Murtaza Frosh](https://wordpress.org/support/users/maimooninc/)
 * (@maimooninc)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/warning-array_shift-expects-parameter-1-to-be-array-error-in-wp-post-loop/#post-2864520)
 * hello Mr. Popper;
 * Thank you for your feedback. Actually you are right the terms were not published
   properly in WP so I re-published them and it worked. Thanks for your inputs.
 * Regards
    Murtaza Frosh Maimoon Inc.

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

The topic ‘Warning: array_shift() expects parameter 1 to be array error in WP post
loop’ is closed to new replies.

## Tags

 * [custom taxonomy](https://wordpress.org/support/topic-tag/custom-taxonomy/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [post-type](https://wordpress.org/support/topic-tag/post-type/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)
 * [warnings](https://wordpress.org/support/topic-tag/warnings/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Murtaza Frosh](https://wordpress.org/support/users/maimooninc/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/warning-array_shift-expects-parameter-1-to-be-array-error-in-wp-post-loop/#post-2864520)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
