Я сделал пример WP_Query с пояснениями для вас, он возвращает посты типа 'product' с таксономией 'marca', в которых термины установлены в алфавитном порядке.
$query_args = array(
'post_type' => 'product', // The post type we want to query, in our case 'product'.
'orderby' => 'title', // Return the posts in an alphabetical order.
'order' => 'ASC', // Return the posts in an ascending order.
'posts_per_page' => -1, // How many post we want to return per page, -1 stands for no limit.
'tax_query' => array( // Taxonomy query
array(
'taxonomy' => 'marca', // The taxonomy we want to query, in our case 'marca'.
'operator' => 'EXISTS' // Return the post if it has the selected taxonomy with terms set, in our case 'marca'.
)
)
);
$query = new WP_Query( $query_args );
if( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo the_title();
}
}
РЕДАКТИРОВАТЬ: А вот код, который вы можете вставить в фрагмент кода.Перехватывает woocommerce_product_query
и изменяет запрос на всех страницах архива.
function custom_woocommerce_product_query( $query ){
$query->set( 'orderby', 'title' ); // Return the posts in an alphabetical order.
$query->set( 'order', 'ASC' ); // Return the posts in an ascending order.
$tax_query = array(
'taxonomy' => 'marca', // The taxonomy we want to query, in our case 'marca'.
'operator' => 'EXISTS' // Return the post if it has the selected taxonomy with terms set, in our case 'marca'.
);
$query->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'custom_woocommerce_product_query', 10, 1 );