I’m trying to make a “Meal of the month” section on a website. The menu is split in custom post types so I need to be able to loop the category from multiple post types.
This is the code I have so far which does absolutely nothing:
<div class="maaltijd-vdm col-1-1">
<?php $mvdm = new WP_Query( array( 'category_name' => 'mvdm', 'posts_per_page' => 1 ) ); ?>
<?php while ($mvdm->have_posts()) : $mvdm->the_post(); ?>
<div class="mvdm-thumb">
<?php the_thumbnail(); ?>
</div>
<div class="description">
<h3><?php the_title(); ?></h3>
<p><?php get_the_mvdm(); ?></p>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
I would really appreciate your help!
*get_the_mvdm is a custom function
*I already have a news loop in the same page with the same code (except variable name)
To query for multiple posttypes, you can pass an array of the post-type slugs to the query.
You must use tax_query for get posts by category.
Try this code:
Hope you find your solution.
This worked for me: