【问题标题】:Wordpress custom post by custom fileds自定义字段的 Wordpress 自定义帖子
【发布时间】:2016-07-22 04:57:07
【问题描述】:

我有一个自定义帖子类型和一个自定义字段:expired_date
我想显示帖子没有过期,所以基本上我想检查如果expired_date > current_date,帖子会显示。

如何执行这个 WordPress 循环查询?

<?php
    $args = array(
        'post_type' => 'job_listing'

    );

    query_posts($args);
    ?>
        <?php while (have_posts()) : the_post(); ?>

你能帮我在自定义帖子查询中检查吗?

【问题讨论】:

  • 更正 Wordpress 拼写!!

标签: wordpress custom-post-type


【解决方案1】:
$today = date('Ymd');
$args = array(
    'post_type' => 'job_listing',
    'meta_key' => 'the_date',
    'meta_query' => array(
        array(
            'key' => 'the_date',
            'value' => $today,
            'compare' => '>='
        )
    ),
    'orderby' => 'meta_value_num',
    'order' => 'ASC'
);

$your_custom_query = new WP_Query($args);

希望会有所帮助:)

【讨论】:

  • 你想要什么。你的意思是查询没有得到你拥有的正确帖子?
  • 我使用了上面的查询并打印了最后执行的查询,它打印了 SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (6461) ORDER BY meta_id ASC 这是错误的
  • 有什么问题?
猜你喜欢
  • 1970-01-01
  • 2014-01-23
  • 1970-01-01
  • 2016-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-02
  • 2015-10-24
相关资源
最近更新 更多