【问题标题】:How to exclude posts without featured images from custom post type WP_Query如何从自定义帖子类型 WP_Query 中排除没有特色图片的帖子
【发布时间】:2015-06-22 22:46:59
【问题描述】:

我们有以下 WP_Query,它收集所有自定义帖子(id=191 除外)并随机列出它们:

$args_projekte = array(
        'post_type' => 'projekt',
        'posts_per_page' => 18,
        'post__not_in' => array(191),   
        'orderby' => 'rand',
        );
$query_projekte = new WP_Query($args_projekte);

我们如何将此扩展到还排除所有没有特色图片的帖子?

提前感谢您的帮助!

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    在搜索_thumbnail_id 的地方输入meta_query

    $args_projekte = array(
        'post_type' => 'projekt',
        'posts_per_page' => 18,
        'post__not_in' => array(191),   
        'orderby' => 'rand',
        'meta_query' => array(array('key' => '_thumbnail_id'))
    );
    $query_projekte = new WP_Query($args_projekte);
    

    以上验证_thumbnail_id键存在。

    【讨论】:

      猜你喜欢
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 2012-12-11
      • 2021-12-26
      相关资源
      最近更新 更多