php-显示来自多个自定义帖子类型的特定类别的帖子

我正在尝试在网站上制作“每月一餐”部分.菜单分为自定义帖子类型,因此我需要能够从多种帖子类型中循环分类.

这是到目前为止我没有做的代码

<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>

我将衷心感谢您的帮助!

* get_the_mvdm是一个自定义函数

*我已经在同一页面中使用相同的代码创建了新闻循环(变量名称除外)

解决方法:

查询多个posttype,您可以将post-type slug的数组传递给查询.

$args = array(
    'post_type'         => array('cpt1', 'cpt2'),   /* the names of you custom post types */
    'category_name'     => 'mvdm',
    'posts_per_page'    => -1                       /* get all posts */
)

$mvdm = new WP_Query( $args );

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...