Пользовательский запрос пост-таксономии сетки цикла Elementor не работаетPhp

Кемеровские программисты php общаются здесь
Anonymous
Пользовательский запрос пост-таксономии сетки цикла Elementor не работает

Сообщение Anonymous »

Я пытаюсь отобразить только дочерние термины на странице архива термина пользовательской таксономии под названием «Вертикали».

Код: Выделить всё

function filter_elementor_loop_widget_terms($query) {
// Check if it's a taxonomy archive for 'verticals'
if (is_tax('verticals')) {
// Get the current term object
$current_term = get_queried_object();

// Get child terms of the current term
$args = array(
'taxonomy'   => 'verticals',
'child_of'   => $current_term->term_id,
'hide_empty' => false,  // Set to true if you want to hide empty terms
'fields'     => 'ids', // We only need the IDs
);

$child_terms = get_terms($args);

if (!empty($child_terms) && !is_wp_error($child_terms)) {
// Modify the query to include only child terms
$query->set('post_type', 'any'); // This ensures we're adding a tax_query and not replacing it
$query->set('tax_query', array(
array(
'taxonomy' => 'verticals',
'field'    => 'term_id',
'terms'    => $child_terms,
),
));
} else {
// Ensure no results are returned if no child terms are found
$query->set('tax_query', array(
array(
'taxonomy' => 'verticals',
'field'    => 'term_id',
'terms'    => array(0), // This ensures no results
),
));
}
}
}
add_action('elementor/query/child_verticals_terms', 'filter_elementor_loop_widget_terms');
Это вообще ничего не отображает. Я пробовал и другие варианты, но безуспешно.
Я даже пытался указать идентификаторы руководства запроса для отображения терминов, но это тоже не работает.
Поэтому я предполагаю, что что-то не так с тем, как я пытаюсь применить этот крючок.
Прямо под этой книгой я создал еще один крючок для фильтрации сообщений по их названию, и это сработало. хорошо.

Подробнее здесь: https://stackoverflow.com/questions/785 ... ot-working

Вернуться в «Php»