$value) { $all_post_types[] = $key; } $tax_query = ''; if (isset($_POST['king_addons_category']) && $_POST['king_addons_category'] != '') { $tax_query = array( array( 'taxonomy' => sanitize_text_field($_POST['king_addons_option_post_type'] ?? ''), 'field' => 'term_id', 'terms' => sanitize_text_field($_POST['king_addons_category']), ), ); } else if (isset($_POST['king_addons_category']) && $_POST['king_addons_category'] == 0 && isset($_POST['king_addons_query_type']) && $_POST['king_addons_query_type'] != 'all') { if (!empty($_POST['king_addons_option_post_type'])) { $tax_query = array( array( 'taxonomy' => sanitize_text_field($_POST['king_addons_option_post_type']), 'field' => 'term_id', 'terms' => sanitize_text_field($_POST['king_addons_category']), ), ); } else { $taxonomy_type_string = sanitize_text_field($_POST['king_addons_taxonomy_type'] ?? ''); if (strpos($taxonomy_type_string, ' ') !== false) { $taxonomy_types = explode(' ', $taxonomy_type_string); $tax_query = [ 'relation' => 'OR' ]; foreach ($taxonomy_types as $taxonomy_type) { $tax_query[] = [ 'taxonomy' => $taxonomy_type, 'operator' => 'EXISTS' ]; } } else { $tax_query = array( array( 'taxonomy' => sanitize_text_field($_POST['king_addons_taxonomy_type'] ?? ''), 'operator' => 'EXISTS', ), ); } } } if ((isset($_POST['king_addons_category']) && $_POST['king_addons_category'] == 0) || (isset($_POST['king_addons_query_type']) && $_POST['king_addons_query_type'] === 'all')) { $tax_query = []; } $can_view_protected_posts = current_user_can('read_private_posts'); $query_args = [ 'posts_per_page' => sanitize_text_field($_POST['king_addons_number_of_results']), 's' => sanitize_text_field($_POST['king_addons_keyword']), 'post_type' => $_POST['king_addons_query_type'] === 'all' || !king_addons_freemius()->can_use_premium_code__premium_only() ? $all_post_types : [sanitize_text_field($_POST['king_addons_query_type'])], 'offset' => sanitize_text_field($_POST['king_addons_search_results_offset']), 'meta_query' => 'yes' === sanitize_text_field($_POST['king_addons_exclude_without_thumb']) ? [['key' => '_thumbnail_id']] : '', 'tax_query' => $tax_query, 'post_status' => 'publish', ]; if (!$can_view_protected_posts || 'yes' !== sanitize_text_field($_POST['king_addons_show_ps_pt'])) { $query_args['post_password'] = ''; } $the_query = new WP_Query($query_args); if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); $post_thumb = has_post_thumbnail() ? get_the_post_thumbnail(get_the_ID(), 'medium') : ''; $post_url = esc_url(get_the_permalink()); $target = esc_attr($_POST['king_addons_ajax_search_link_target']); $show_thumbnail = ('yes' === sanitize_text_field($_POST['king_addons_show_ajax_thumbnail'])); $can_show_content = (!post_password_required() || $can_view_protected_posts); ?>
  • ' . esc_html(sanitize_text_field($_POST['king_addons_no_results'] ?? '')) . '

    '; } endif; die(); } } new Search_Ajax();