- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi,
I’ve been Googling around but can’t seem to find a snippet for my problem.
I have two custom post types – Foods, Promos. Now I have a section on my homepage where I want to show 3 ‘featured’ items either from the Promos or Foods with a tag of ‘featured’.
So basically I just want a snippet to show 3 posts with a tag = ‘featured’ from those two custom post type. I am able to show post with a tag of ‘featured’ but only from Foods or only from Promos.
Thanks.
Ok, I’ve managed to do it but really not sure if it’s even the best way to do it.
`
<ul class=”featured-list”>
<?php
$type = array(‘promo’, ‘food’);
$args = array(
‘tag’ => ‘featured’,
‘post_type’ => $type,
‘post_status’ => ‘publish’,
‘numberposts’ => 3
);
$my_query = null;
$my_query = new WP_Query($args);
if($my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>
<div class="promo-thumb">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/default-featured-thumb.png" alt="">
<?php } ?>
</div>
<h3 class="promo-name"><?php the_title(); ?></h3>
<div class="promo-desc"><?php the_content(); ?></div>
<a href="#" class="button">Read more</a>
</li>
<?php
endwhile;
}
wp_reset_query();
?>
</ul>
`