我在Proximos Eventos标题中有www.colegiodepsicologos.org.gt,它显示了来自posttype“eventos”的未来帖子,但当你点击它们显示未找到时,我如何更改该行为以显示未来的帖子单?
谢谢!
答案 0 :(得分:2)
完成!
add_filter(‘the_posts’, ‘show_future_posts’);
function show_future_posts($posts){
global $wp_query, $wpdb;
if(is_single() && $wp_query->post_count ==0){
$posts = $wpdb->get_results($wp_query->request);
}
return $posts;
};
答案 1 :(得分:2)
小心; Jepser 的答案也将显示已删除/删除的帖子,您可能不想显示这些帖子。
这将仅限于未来的帖子(在WP 3.9.2上测试):
add_filter('the_posts', 'show_future_posts');
function show_future_posts($posts)
{
global $wp_query, $wpdb;
if(is_single() && empty($posts)) //detect cases where WP usually shows 404
{
$posts = $wpdb->get_results($wp_query->request);
//make sure it only affects future posts, not trashed
if(isset($posts[0]->post_status)&&$posts[0]->post_status!='future'){
$posts=array();
}
}
return $posts;
}