Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:01:26+00:00 2026-05-28T14:01:26+00:00

Warning: array_pop() expects parameter 1 to be array, null given in … on line

  • 0

Warning: array_pop() expects parameter 1 to be array, null given in … on line 34

I get the following error when using the following function. The output of the function works as expected except the error shows up before the output.

<?php 
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)
  if($rpost){
    //don't take duplicates
    if(!isset($posts[$rpost->ID])){
      $posts[$rpost->ID] = $rpost;
      $count++;
    }
  }
  $index = ($index % 3); //rotate through the 4 term arrays
}
foreach($posts as $post){
    setup_postdata($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(); ?>    

                    </div>
<?php } ?>

Does anyone have any experience with this error or see what might be causing it?

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:01:27+00:00Added an answer on May 28, 2026 at 2:01 pm

    The problem is that you’re using array_pop on an index of the potentials array.
    array_pop is designed to pop the last element off the end of an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error in my image upload code: Warning: getimagesize(Array) [function.getimagesize]: failed
im currently getting these error on my site: Warning: array_keys() [function.array-keys]: The first argument
Warning: array_filter() expects parameter 2 to be a valid callback, function 'empty' not found
I have this code: array = ['notice', 'warning', 'error'] array.delete('notice') if flash[:notice] array.delete('warning') if
I am still new to PHP. My problem: Warning: array_push() expects parameter 1 to
call_user_func('array_pop', $myarray); gives 'Parameter 1 to array_pop() expected to be a reference, value given',
I used to use the function below for an array or IP's but now
why would this $trader_details = array_walk($trader_details, 'htmlspecialchars'); give this error? Severity: Warning Message: htmlspecialchars()
I need to convert a (possibly) null terminated array of ascii bytes to a
Is it possible to array_push to a multidimensional array? Creating the array using: $ObjectArray

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.