显示具有自定义日期元值的wordpress帖子,按此日期排序,

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了显示具有自定义日期元值的wordpress帖子,按此日期排序,相关的知识,希望对你有一定的参考价值。

First you have to add a custom value with a correct date format.
The lines:
`AND CAST(wpostmeta.meta_value AS DATE) > '".date("Y-m-d H:i:s")."'
AND CAST(wpostmeta.meta_value AS DATE) < '".date("Y-m-d H:i:s", $date2)."' `
are only used to select dates between the current day and 2 months later
  1. $myrows = $wpdb->get_results("
  2. SELECT wposts.post_title, wposts.ID , wpostmeta.meta_key, wpostmeta.meta_value
  3. FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
  4. WHERE wposts.ID = wpostmeta.post_id
  5. AND wposts.post_type = 'concerts'
  6. AND wpostmeta.meta_key = 'DateConcert'
  7. AND CAST(wpostmeta.meta_value AS DATE) > '".date("Y-m-d H:i:s")."'
  8. AND CAST(wpostmeta.meta_value AS DATE) < '".date("Y-m-d H:i:s", $date2)."'
  9. AND wposts.post_status = 'publish'
  10. ORDER BY CAST(wpostmeta.meta_value AS DATE) ASC
  11. ");
  12. if ($myrows) :
  13. foreach ($myrows as $post) :
  14. setup_postdata($post);
  15. ?>
  16. <h2><a href="<?php the_permalink(); ?>" rel="bookmark"
  17. title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
  18. <?php
  19. endforeach;
  20. else :
  21. ?>
  22. <h2> Not Found</h2>
  23. <?php endif; ?>

以上是关于显示具有自定义日期元值的wordpress帖子,按此日期排序,的主要内容,如果未能解决你的问题,请参考以下文章

Wordpress 自定义 SQL 以获取三个具有给定元值的帖子

WordPress WP_Query:根据自定义元值显示自定义帖子类型,并按另一个自定义元值排序

Wordpress 在自定义帖子类型存档页面上按日期排序

mysql返回最大n个具有相同值的行

排除元值空wordpress的帖子

php WordPress事件按元值日期排序