get_posts not returning correct image and permalink
-
I am trying to show all posts that have a specific post type (either ‘dog’ or ‘cat’) and have the field ‘virtual_adoption’ set to ‘1’.
I’ve coded for the ‘dog’ and ‘cat’ in the same way. The ‘dog’ is working fine, but the ‘cat’ only bring the permalink and image for the page, not for the specific cat.
It seems the ‘dog’ is ‘in the loop’ and the ‘cat’ not.
Why isn’t it working the same for both of the post types? How do I get the ‘cat’ to bring the ‘cat’ permalink and image?<?php $posts = get_posts(array( 'post_type'=> 'dog', 'meta_query' => array( array( 'key' => 'virtual_adoption', 'value' => '1', 'compare' => '==' ) ) )); $posts_c = get_posts(array( 'post_type'=> 'cat', 'meta_query' => array( array( 'key' => 'virtual_adoption_cats', 'value' => '1', 'compare' => '==' ) ) )); ?> <?php foreach( $posts as $post ): setup_postdata( $post ) ?> <div style="display: table-row;" class="vrow"> <div style="display: table-cell;" class="virtual_image"> <?php if ( has_post_thumbnail()) the_post_thumbnail('pet-image'); ?> </div> <div style="display: table-cell;" class="virtual_name"> <a>"><?php echo "Sponsor "; echo the_title(); echo ':'; ?></a> <span class="field_v_label"> <?php echo ' Age:'; ?> </span> <?php echo get_field( "age_range_dog" ); ?> <span class="field_v_label"> <?php echo ' Information:'; ?> </span> <span class = "field_v_content"><?php the_content(); ?></span> </div> </div> <?php endforeach; ?> <?php wp_reset_postdata(); ?> <?php foreach( $posts_c as $post_c ): setup_postdata( $post_c ) ?> <div style="display: table-row;" class="vrow"> <div style="display: table-cell;" class="virtual_image"> <?php if ( has_post_thumbnail()) the_post_thumbnail('pet-image'); ?> </div> <div style="display: table-cell;" class="virtual_name"> <a>"><?php echo "Sponsor "; echo the_title(); echo ':'; ?></a> <span class="field_v_label"> <?php echo ' Age:'; ?> </span> <?php echo get_field( "age_range_cat" ); ?> <span class="field_v_label"> <?php echo ' Information:'; ?> </span> <span class = "field_v_content"><?php the_content(); ?></span> </div> </div> <?php endforeach; ?> <?php wp_reset_postdata(); ?> </div>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘get_posts not returning correct image and permalink’ is closed to new replies.