• Resolved wphax

    (@wphax)


    I’m having a problem, if you look at https://wphax.com you’ll see that there’s no PHP errors. On localhost (using xampp for a server), I am getting the following error:

    Warning: in_array() expects parameter 2 to be array, null given in C:\xampp\htdocs\wordpress\wp-content\themes\wphax\index.php on line 124

    And here is the loop that is apparently having the problem:

    <?php $tempo_query = new WP_Query('category_name=blog&posts_per_page=1');
    			  while ($tempo_query->have_posts()) : $tempo_query->the_post();
    			  if (in_array($post->ID, $do_not_duplicate)) continue; ?>

    My first loop looks like this, so $do_not_duplicate should be an array…

    <?php $my_query = new WP_Query('category_name=portfolio&posts_per_page=2&offset=2');
                          while ($my_query->have_posts()) : $my_query->the_post();
                          $do_not_duplicate[] = $post->ID; ?>

    Can anybody tell me what’s going on?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi does your local version have the same content as your online version? One quick way to correct this may be to simply instantiate $do_not_duplicate outside of the while loop as an empty array $do_not_duplicate = array()

    Thread Starter wphax

    (@wphax)

    I’m not really sure what you mean or what I would do to fix that, could you explain a little more?

    Not a Problem.

    The message you see: Warning: in_array() expects parameter 2 to be array, null given in
    usually occurs when a variable is initially set to null and then never further modified. I suspect that the first loop locally is never adding any entries into the $do_not_duplicate array and as such it is defined as null causing the error.

    To check place $do_not_duplicate = array(); before this statement in the code

    $my_query = new WP_Query('category_name=portfolio&posts_per_page=2&offset=2');
                          while ($my_query->have_posts()) : $my_query->the_post();
                          $do_not_duplicate[] = $post->ID;

    in the code and see if the error is gone.

    Thread Starter wphax

    (@wphax)

    That works, thanks a lot. Looks great on localhost now and on the web.

    ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting error on localhost (xampp), but not online — problem with the loop’ is closed to new replies.