vendredi 29 août 2014

error Invalid argument supplied for foreach() for the second foreach in the code


Vote count:

0




in my code below the data is extracted correctly but i still get the error Warning: Invalid argument supplied for foreach() for line 24 i.e foreach ($authorlist as $post)


below is my code



<?php

$all= get_posts(array('post_type' => 'books', 'numberposts' => -1,));

foreach ( $all as $post ) : setup_postdata($post);

if (!empty($post))
{
$booklink = array();

$booklist = strip_tags(get_field('booklist'));
foreach ($booklist as $post) : setup_postdata($post);
if (!empty($post))
{
$booklink[] = strip_tags(get_field('booklink',$post));
}
endforeach;
wp_reset_postdata();
echo $booklink[0];

$authorname = array();

$authorlist = strip_tags(get_field('booklist'));
foreach ($authorlist as $post) : setup_postdata($post);
if (!empty($post))
{
$booklink[] = strip_tags(get_field('authorname',$post));
}
endforeach;
wp_reset_postdata();
echo $authorname[0];

}
endforeach;
?>


asked 46 secs ago







error Invalid argument supplied for foreach() for the second foreach in the code

Aucun commentaire:

Enregistrer un commentaire