@anriko

Как переписать функцию для исклучение категории id 154 wordpress?

public function _ajax_get_search_results()
    {
        global $wpdb;

        if (isset($_POST['searchQuery'])) {
            $queries = json_decode(stripslashes($_POST['searchQuery']));
            $query_args = [
                's' => sanitize_text_field($queries->queryString),
                'post_type' => 'any',
                'exclude'     => array(154),*/
            ];
            if (!empty($queries->productCat)) {
                $query_args['post_type'] = 'product';
                if ($queries->productCat != 'all') {
                    $query_args['tax_query'][] = [
                        'taxonomy' => 'product_cat',
                        'terms' => intval($queries->productCat),
                      
                    ];
                }
            }
            if (zoo_customize_get_setting('header_search_box_by_product_sku_only')) {
                $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", sanitize_text_field($queries->queryString)));
                if ($product_id) {
                    $query_args = [
                        'post_type' => 'product',
                        'p' => intval($product_id)
                    ];
                }
            }
            $search_result = apply_filters('zoo_search_box_ajax_results', get_posts($query_args), $queries);
            ob_start();
            if ($search_result && is_array($search_result)) {
                global $post;
                ?>
                <div class="wrap-search-result">
                    <ul class="list-search-result">
                        <?php foreach ($search_result as $post) : setup_postdata($post); ?>
                            <li class="search-result-item">
                                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                                    <div class="wrap-img-result">
                                        <?php the_post_thumbnail('thumbnail'); ?>
                                    </div>
                                    <div class="wrap-result-content">
                                        <h3 class="title-result"><?php the_title(); ?></h3>
                                        <?php
                                        if ('product' === $post->post_type && class_exists('WC_Product')) { ?>
                                            <p class="price amount">
                                                <?php
                                                $prdct = new WC_Product($post->ID);
                                                echo wp_kses_post($prdct->get_price_html());
                                                ?>
                                            </p>
                                            <?php
                                        } else {
                                            echo zoo_strip_all_shortcodes(get_the_excerpt());
                                        } ?>
                                    </div>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </div>
                <?php
                wp_reset_postdata();
            } else {
                ?><div class="wrap-search-result no-result"><?php esc_html_e('No result found!', 'cerato'); ?></div><?php
            }
            $output = ob_get_contents();
            ob_end_clean();
            echo wp_kses_post($output);
            exit;
        }
    }
}
  • Вопрос задан
  • 62 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы