此代码仅显示较少的日期或等于今天的日期。
如何显示过期帖子?
It\'s a code
add_action( \'pre_get_posts\', \'custom_post_type_archive_eventos\' );
function custom_post_type_archive_eventos( $query ) {
if( $query->is_main_query() && !is_admin() ) {
$today = date(\'Y-m-d\');
$query->set( \'posts_per_page\',\'6\' );
$query->set( \'meta_query\', array(
\'relation\' => \'OR\',
array(
\'key\' => \'Data_START\',
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'DATE\',
),
array(
\'key\' => \'Data_END\',
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'DATE\',
),
));
}
}
最后,我需要执行以下命令:
1) 未过期的帖子
2) 休息。。。(过期帖子)
UPDATE(更新)存在3种类型的贴子,有自定义文件和没有自定义文件。
1) 无自定义字段的发布
2) 仅使用自定义字段发布:
Data_START
: 2018-02-20
3) 使用两个自定义字段发布:
Data_START
2018-02-20
Data_END
2018-02-22
And so
---> 无数据
--->仅开始数据:2018-02-20
---开始和结束数据:2018-02-20 2018-02-22
我需要首先显示所有有效的帖子和休息(所有过期和无数据帖子)
SO网友:saddamcr7
Here is the Code
function university_adjust_queries( $query ) {
if ( ! is_admin() && is_post_type_archive( \'program\' ) && $query->is_main_query() ) {
$query->set( \'orderby\', \'title\' );
$query->set( \'order\', \'ASC\' );
$query->set( \'posts_per_page\', -1 );
}
if ( ! is_admin() && is_post_type_archive( \'event\' ) && $query->is_main_query() ) {
$today = date( \'Ymd\' );
$query->set( \'meta_key\', \'event_date\' );
$query->set( \'orderby\', \'meta_value_num\' );
$query->set( \'order\', \'ASC\' );
$query->set( \'meta_query\', array(
array(
\'key\' => \'event_date\',
\'compare\' => \'>=\',
\'value\' => $today,
\'type\' => \'numeric\',
)
) );
}
}
add_action( \'pre_get_posts\', \'university_adjust_queries\' );