【问题标题】:exclude posts with meta value empty wordpress排除元值空wordpress的帖子
【发布时间】:2012-06-13 12:27:05
【问题描述】:

我创建了一个自定义字段“复选框”。我只想排除选中复选框的帖子。 我不能这样做。 这是我正在使用的代码

$args = array(
                'posts_per_page'=> -1,
                 'post_type' => 'latestnews',
                 'orderby'=> 'id',
                 'meta_key'=>'',
                 'meta_value'=>'',
                 'order'=> 'asc',
                );
            query_posts($args);
    $my_posts = new WP_Query($args);

所以基本上我只想要没有设置元键“粘性”并且元值不存在的帖子。 这里我的元键是一个复选框,如果我选中复选框,则值 yes 存储在数据库中,如果我不选中该选项,则数据库中不会存储任何内容。

【问题讨论】:

    标签: wordpress


    【解决方案1】:
    <?php
    $check_metakey = get_post_meta($post->ID, "sticky", true);
    if($check_metakey !== '') :
    ?>
    your article's template
    <?php
    endif;
    ?>
    

    注意:所有这些都在 while 循环中。

    祝你好运! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 2013-10-29
      • 2017-06-29
      • 1970-01-01
      • 2011-08-10
      相关资源
      最近更新 更多