function bla_bla_bla_post_class($classes, $product)
{
$classes[] = 'col-12';
$classes[] = 'col-md-3';
$classes[] = 'col-sm-6';
return $classes;
}
add_filter('woocommerce_post_class', 'bla_bla_bla_post_class', 10, 2);
add_action( 'pre_get_posts', function( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set( 'post__not_in', [1.2.3.4.5.6] ); // id записей которые надо скрыть
$tax_query = [
[
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => [20,30,40,50], // id категорий которые надо скрыть
'operator' => 'NOT IN',
]
];
$query->set( 'tax_query', $tax_query );
}
});
add_filter( 'pre_option_comment_moderation', 'wpp_auto_comment_moderation' );
add_filter( 'pre_option_comment_whitelist', 'wpp_auto_comment_moderation' );
function wpp_auto_comment_moderation( $option ) {
global $post;
$need_id = 55; #ID категории в ноторой надо разрешить автопубликацию комментариев
$ids = wp_get_post_categories( $post->ID );
if ( in_array( $need_id, $ids ) ) {
return 0;
} else {
return $option;
}
}
// добавить в functions.php
/**
* Получение термина верхнего уровня
*
* @param $term_id int ID термина
* @param $taxonomy string таксономия
*
* @return array|int|null|WP_Error|WP_Term
*/
function wpp_get_term_top_level_id( $term_id, $taxonomy ) {
$term_parent = 0;
while ( $term_id ) {
$term = get_term( $term_id, $taxonomy );
$term_id = $term->parent;
$term_parent = $term;
}
return $term_parent;
}
// Start the loop.
while ( have_posts() ) : the_post();
$terms = get_the_terms( get_the_ID(), 'БББ' );
if(!empty($terms)) {
$need_term = wpp_get_term_top_level_id( $terms[0]->term_id, 'БББ' );
get_template_part( 'taxonomy/content-taxonomy/content-taxonomy', $need_term->slug);
} else {
echo 'не установлены термины таксономии БББ';
}
$results_rating = $wpdb->get_col("SELECT * FROM $table_name");
[10,11,12,13,14,15]
$post_id= $rowes->id;
foreach ($results_rating as $rowes)
$post_id = $rowes
$post_id= end($results_rating)
<?php
/**
* Template Name: Бла бла бла
*/
get_header();
$args = [
'post_type' => 'product',
'tax_query' => [
[
'taxonomy' => 'product_cat',
'field' => 'name',
'terms' => 'Tem Name',
],
],
'posts_per_page' => - 1,
];
global $wp_query;
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) :
woocommerce_product_loop_start();
?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile;
woocommerce_product_loop_end();
?>
<?php else : ?>
<div>Товаров не найдено</div>
<?php endif;
get_footer();