wordpress - PHP Warning: Warning: array_shift() expects parameter 1 to be array -


warning: array_shift() expects parameter 1 array, object given in /hermes/walnaweb01a/b1374/moo.peachdesigninccom/tools4hardwood/wp-content/themes/listings/homepage_loops/content-listingsum.php on line 18 

is error i'm getting on page http://www.tools4hardwoods.com/home-2/ , i'm having no luck. can 1 me debug?

heres full code:

<div class="car-list">     <div class="car-img">         <?php if(has_post_thumbnail()): ?>             <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail("home_listing"); ?></a>         <?php endif; ?>     </div>     <div class="car-info">         <a href="<?php the_permalink(); ?>"><h3><?php the_title(); ?></h3></a>         <h2 class="car-price"><?php get_listing_price(); ?></h2>         <ul class="car-tags clear">             <?php             global $post;             $configuration = get_listing_display_attributes($post->id);             if ($configuration):                 foreach ($configuration $tax) {                     $terms = get_the_terms($post->id,$tax);                     if ($terms):                         $term = array_shift($terms);                         $term_link = get_term_link($term->slug,$term->taxonomy);                         $term_name = $term->name;                         $taxonomy = get_taxonomy($term->taxonomy);                         ?>                         <a href="<?php echo $term_link; ?>"><?php echo $term_name; ?></a>                     <?php                     endif;                 }             endif;             ?>         </ul>     </div>     <div style="clear:both;"></div> </div> 

as pointed out @jeremy, part of code may return wp_error instance:

// may return array, false or wp_error object. $terms = get_the_terms($post->id,$tax); 

so have update conditional, make sure $terms array , not wp_error object.

<?php  global $post; $configuration = get_listing_display_attributes($post->id); if ($configuration):     foreach ($configuration $tax) {         $terms = get_the_terms($post->id,$tax);         // update conditional here.         if (is_array($terms) && ! is_wp_error($terms)):             $term = array_shift($terms);             $term_link = get_term_link($term->slug,$term->taxonomy);             $term_name = $term->name;             $taxonomy = get_taxonomy($term->taxonomy); ?>             <a href="<?php echo $term_link; ?>"><?php echo $term_name; ?></a>         <?php endif;     } endif; ?> 

the is_wp_error() built-in wordpress method check whether passed parameter instance of wp_error class.

hope help!


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -