I'm using this piece of code to pull out cars and the car details in a custom post type within wordpress.
<h1>Cars for Sale</h1>
<?php $args = array( 'post_type' => 'carlistings', 'posts_per_page' => 10 ); ?>
<ul id="carsforsale">
<?php $loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $cardetails = get_post_meta( $post->ID, 'cardetails', true );
foreach( $cardetails as $cardetails ) { ?> <!-- Line # 13 -->
<li class="pop"><span>
<span class="thumb"><a href="<?php the_permalink(); ?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail('thumbnail'); } ?></a></span>
<span class="title"><h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3></span>
<strong>Make</strong> <?php echo $cardetails['make'] ?><br />
<strong>Model</strong> <?php echo $cardetails['model'] ?><br />
<strong>Year</strong> <?php echo $cardetails['year'] ?><br />
<strong>Color:</strong> <?php echo $cardetails['color'] ?><br />
<strong>Price:</strong> <?php echo $cardetails['price'] ?><br />
</span></li>
<?php } ?>
<?php wp_reset_query(); ?>
The problem I have is, that after 3 enteries I get this error message
Warning: Invalid argument supplied for foreach() in /home/styleaut/public_html/wp-content/themes/styleautosales/page-30.php on line 13
line 13 falls on this part of the code:
foreach( $cardetails as $cardetails ) {
$cardetails
is not an array or object – php_nub_qq