1
所以我正在一些自定义事件在WordPress的事件PHP。它适用于事件,它会自动消除旧日期。问题是它不会按升序排列日期。WordPress的PHP(事件)错误
我不是最好的PHP,并得到最初的人的帮助,他不知道为什么它会正确地命令日期。我尝试将asc
切换为desc
,它没有改变任何东西;有一部分代码我评论了一些代码,并且我尝试了基于我在网上找到的解决方案更改了很多代码。
我用完了所有的解决方案,因此我很感谢那里的任何PHP向导的帮助。
下面是与代码的该部分有关的代码。
function format_date($id=null, $string=null){
if (!is_null($id)) {
$date_of_event = get_post_field('date_of_event', $id);
$date_of_event = strtotime($date_of_event);
$event_date_pretty = date("l, F j, Y", $date_of_event);
} else {
//if $id was null and we have something for string use that else set $excerpt to '' so we can retrn nothing instead of an error.
if (!is_null($string)) {
$event_date_pretty = $string;
}
else {
$event_date_pretty = '';
}
}
return $event_date_pretty;
}
function events_func($atts) {
$a = shortcode_atts(array(
'count' => 5,
'orderby' => 'date_of_event',
'order' => 'ASC',
), $atts);
if (!is_numeric($a['count']) || $a['count'] <= 0) { $a['count'] = 5; }
// $order = strtolower($a['order']);
// if ($order !== "ASC" && $order !== 'desc') { $a['order'] = "ASC"; }
// $a['order'] = strtoupper($a['order']);
$type = 'event';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => $a['count'],
'caller_get_posts'=> 1,
'order' => $a['order'],
'meta_key'=>$a['orderby'],
'order' => 'meta_value',
);