Warning: array_pop() needs parameter 1 to become array, null succumbed ... online 34

I recieve the next error while using the following function. The creation of the function works not surprisingly except the mistake turns up prior to the output.

global $post;

//Get the terms for the current post
$terms = get_the_terms( $post->ID , 'character', 'string');
echo $terms[1];
$potentials = array();
$c = 0;
$totalFound = 0;

//Gather your posts for each term
foreach($terms as $term){
   $q = array(
    'character' => $term->slug, //term to retrieve from custom taxonomy
    'numberposts' => 3,  //limit to 4 posts
    'post_type' => 'videos', //get only posts
    'exclude' => $post->ID //exclude current post
   $posts = get_posts($q);
   $totalFound+= count($posts);
   $potentials[$c++] = array_reverse($posts);

$count = 0;  //The number of good posts we've found
$index = 0;  //Number of posts we've tried
$max = $totalFound > 3 ? 3 : $totalFound;  //The max we can find
$posts = array();

//Now pick one post from each term until we reach our quota,
//or have checked them all
while($count < $max){

  //Pop off a post to use
  $rpost = array_pop($potentials[$index++]);

  //if we got a post (if there was one left)
    //don't take duplicates
      $posts[$rpost->ID] = $rpost;
  $index = ($index % 3); //rotate through the 4 term arrays
foreach($posts as $post){
    $exclusive = get('aoexclusive_yes');
    if(!$exclusive) {$exclusive = null;} else {$exclusive = 'exclusive';}
    $image = wp_get_attachment_image_src( get_post_thumbnail_id(  $post->ID ), "video-thumb" );
                    <div class="thumb-post<?php echo ' '.$exclusive; ?>">
<?php if($image) { ?>

                        <a class="featured-image" href="<?php the_permalink(); ?>"><img src="<?php echo $image[0]; ?>" /></a>
<?php } else { ?>

                        <a class="featured-image" href="<?php the_permalink(); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/assets/images/default.jpg" /></a>
<?php } ?>
                        <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php ao_post_meta(); ?>    

<?php } ?>

Does anybody have knowledge about this error or see what may be leading to it?

Code initially originated from http://wordpress.org/support/topic/custom-taxonomy-related-posts-query


The code above is very imperfect. This wordpress plugin works perfectly:


However , you are using array_pop with an index from the potentials array. array_pop is made to pop the final element from the finish of the array.

array_pop() accepts an assortment as argument also it take away the last value in the array (coming back it). If you wish to get the need for that array element, you want to do something similar to

$rpost = $potentials[$index++];

Should you should also take it out of the array, you will want something similar to this:

$rpost = $potentials[$index];