Wordpress: почему не работает order в pre_get_posts?

Не могу понять, почему не работает order
add_filter( 'pre_get_posts' , 'my_change_order' );
function my_change_order( $query ) {
	if($query->is_main_query() && !is_admin()) {
if (is_archive()) {
			$queried_object = get_queried_object();
			$term_id = get_queried_object()->term_id;
			if (isset($term_id)) {
			    $check_option=get_option('cp-sort-term-id-'.$term_id);
				if ($check_option=='true') {
					$query->set( 'orderby' , 'meta_value_num' );
					$query->set( 'meta_key', 'cp-term-id-'.$term_id);
					$query->set( 'order', 'ASC');
					$query->set( 'posts_per_page', -1);
					
				}
			}
		}
	}
	return $query;
}
  • Вопрос задан
  • 2802 просмотра
Решения вопроса 2
Попробуйте вывести переменную wp_query, и проанализировать запрос. Может что то упустили
Не вижу логики в
$queried_object = get_queried_object();
$term_id = get_queried_object()->term_id;

при том что $queried_object давлее в коде нигде не встречается
Ответ написан
maxxannik
@maxxannik
Сайты на WordPress + Интернет магазины WooCommerce
ну а написать что причина была в кривом плагине по соседству?
и что все решилось тем что кривой плагин был удален?
надо же оставить потомкам решение :)
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
redmo
@redmo Автор вопроса
WP_Query Object ( [query_vars] => Array ( [cat] => 1 [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => cp-term-id-1 [meta_value] => [preview] => [s] => [sentence] => [fields] => [menu_order] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) [orderby] => meta_value_num [order] => ASC [posts_per_page] => -1 ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [0] => Array ( [taxonomy] => category [terms] => Array ( [0] => 1 ) [include_children] => 1 [field] => term_id [operator] => IN ) ) [relation] => AND ) [meta_query] => [date_query] => [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => 1 [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => 1 [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_404] => [is_comments_popup] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash] => bdb05ea4d6d92b44dd19c966f50adf82 [query_vars_changed] => [thumbnails_cached] => [stopwords:private] => [query] => Array ( [cat] => 1 ) [queried_object] => stdClass Object ( [term_id] => 1 [name] => Рубрика по умолчанию [slug] => %d0%b1%d0%b5%d0%b7-%d1%80%d1%83%d0%b1%d1%80%d0%b8%d0%ba%d0%b8 [term_group] => 0 [term_taxonomy_id] => 1 [taxonomy] => category [description] => [parent] => 0 [count] => 6 [filter] => raw [cat_ID] => 1 [category_count] => 6 [category_description] => [cat_name] => Рубрика по умолчанию [category_nicename] => %d0%b1%d0%b5%d0%b7-%d1%80%d1%83%d0%b1%d1%80%d0%b8%d0%ba%d0%b8 [category_parent] => 0 ) [queried_object_id] => 1 )
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы