我已经绕圈子走了好几个星期-我似乎无法按标题将我的自定义帖子类型排序-
我有一个具有附近功能的自定义搜索,因此希望保留该功能-我的自定义帖子查询按标题相关性显示在WP Admin一侧,而不显示在正面。
我已找到有关pre_fetch帖子的代码,并将meta从orderby的“ date”更改为“ title”,将“ DESC”更改为“ ASC”-清除了缓存服务器和浏览器端,但仍然不高兴。
我认为这应该真的很容易,但是我在这里所做的任何更改似乎都没有用-SQL是否已缓存了我之前的错误查询,并且仍在返回?
这里有任何关于这个令人困惑的问题的建议
已经厌倦了在args.php中添加arg来覆盖oder,但不起作用
如上所述,已更改自定义邮政编码,以尝试按标题ASC而非日期DESC返回查询,但此处的查询结果也未更改
/**
* filter orderby
*/
if (isset($_REQUEST['sortby'])
&& ( $query->is_main_query() || (isset($query->query_vars['meta_key']) && $query->query_vars['meta_key'] == 'rating_score_comment') )
) {
if ($_REQUEST['sortby'] !== 'date') {
// $query->query_vars['meta_key'] = $_REQUEST['sortby'];
$query->set('orderby', 'meta_value_num');
} else {
// order by date
$query->set('orderby', 'date');
}
// order desc
$query->set('order', 'DESC');
}
// order by rating score
if(isset($_REQUEST['query']['orderby']) && $_REQUEST['query']['orderby'] == 'rating_score_comment') {
$query->set('orderby', 'meta_value_num date');
if( !isset($_REQUEST['query']['meta_key'] ) ) {
$query->query_vars['meta_key'] = $_REQUEST['query']['orderby'];
$query->meta_query = array(
//check to see if et_featured has been filled out
'relation' => 'OR',
array(
//check to see if date has been filled out
'key' => $_REQUEST['query']['orderby'],
'compare' => 'BETWEEN',
'value' => array(
0,
5
)
),
array(
//if no et_featured has been added show these posts too
'key' => $_REQUEST['query']['orderby'],
'value' => '',
'compare' => 'NOT EXISTS'
)
);
}else{
// order by rating score for feature block
if($_REQUEST['query']['meta_key'] == 'et_featured') {
$query->set('orderby', 'menu_order');
$query->set('meta_query' , array(
array(
'key' => 'rating_score_comment',
// 'value' => array(0, 5),
// 'compare' => 'BETWEEN'
),
array(
'key' => 'et_featured',
'value' => '1',
'compare' => 'LIKE'
)
));
}
if($_REQUEST['query']['meta_key'] == 'de_event_post') {
// order by rating score for event block
$query->set('orderby', 'menu_order');
$query->set('meta_query' , array(
array(
'key' => 'rating_score_comment',
'value' => array(0, 5),
'compare' => 'BETWEEN'
),
array(
'key' => 'de_event_post',
'value' => '',
'compare' => '!=',
'type' => 'NUMERIC'
)
));
}
}
}
// Orderby featured
// if(is_search()){
// $query->set('meta_key', 'et_featured');
// $query->set('orderby', 'meta_value_num date');
// }
$is_search = ! (empty($_REQUEST['query']) || empty($_REQUEST['query']['s']));
if ((et_load_mobile() && !is_single() ) && !$is_search && (isset($query->query_vars['orderby']) && $query->query_vars['orderby'] != 'rand')) {
if (!is_author() && isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == $this->post_type) {
if(!isset($query->query_vars['near_lat']) || $query->query_vars['near_lat'] == '' ){
$query->set('orderby', 'meta_value_num date');
}
// if (isset($query->query_vars['meta_value'])) {
// unset($query->query_vars['meta_value']);
// }
$query->meta_query = array(
//check to see if et_featured has been filled out
'relation' => 'OR',
array(
//check to see if date has been filled out
'key' => 'et_featured',
'compare' => 'IN',
'value' => array(
0,
1
)
) ,
array(
//if no et_featured has been added show these posts too
'key' => 'et_featured',
'value' => 1,
'compare' => 'NOT EXISTS'
)
);
}
}
return $query;
}
/**
* filter order and replace menu_order by mt1.value
* mt1.meta_value is the meta value when join with table post meta base on rating_score meta key
* @param String $orderby Wordpress post query orderby string
* @return String
*
* @since 1.8.5
* @author Dakachi
*/
function orderbyreplace($orderby) {
global $wpdb;
return str_replace($wpdb->posts.'.menu_order', 'mt1.meta_value+0', $orderby);
}
/**
* catch event change ad status, update expired date