Using a Custom Field Value as an $args for WP_Query
-
I think I am close to figuring out my issue, and my problem is probably just sematics.
On a Page, after the loop I want to Query 5 posts with their feature images from a specific category ID. The Category ID is coming from a custom field.
The below code works except for 1 thing… It isn’t narrowing the query by the Category ID. IT is only showing the 5 most recent posts.
Thanks for any help!
<?php if(get_post_meta($post->ID, 'Category_ID', true) ): ?> <?php $args=array( 'showposts' => 5, 'cat' => echo $Category_ID, ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <div class="child-thumb"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> </div> <?php endwhile; } //if ($my_query) ?> <?php wp_reset_query() ?> <?php endif; ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Using a Custom Field Value as an $args for WP_Query’ is closed to new replies.