public function search( WP_REST_Request $request ) { $term = sanitize_text_field( $request->get_param('search') ); if ( empty( $term ) ) { return [ 'ok' => false, 'message' => 'Kein Suchbegriff' ]; } error_log( '!!! SEARCH: ' . $term ); $results = []; $found_ids = []; /* |-------------------------------------------------------------------------- | SONDERFALL 1: Chipnummer (15-stellige Zahl) |-------------------------------------------------------------------------- */ if ( preg_match('/^\d{15}$/', $term) ) { global $wpdb; $id = $wpdb->get_var( $wpdb->prepare( " SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product' AND post_status = 'publish' AND ( post_content LIKE %s OR post_excerpt LIKE %s ) LIMIT 1 ", '%Chip:%' . $wpdb->esc_like($term) . '%', '%Chip:%' . $wpdb->esc_like($term) . '%' ) ); if ( $id ) { $post = get_post($id); $results[] = $this->format_result( $post ); } return [ 'ok' => true, 'search_term' => $term, 'count' => count($results), 'results' => $results ]; } /* |-------------------------------------------------------------------------- | SONDERFALL 2: Ear / OM Nummer (reine Zahlen) |-------------------------------------------------------------------------- */ if ( preg_match('/^\d+$/', $term) ) { global $wpdb; $id = $wpdb->get_var( $wpdb->prepare( " SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product' AND post_status = 'publish' AND ( post_content LIKE %s OR post_excerpt LIKE %s ) LIMIT 1 ", '%OM:%' . $wpdb->esc_like($term) . '%', '%OM:%' . $wpdb->esc_like($term) . '%' ) ); if ( $id ) { $post = get_post($id); $results[] = $this->format_result( $post ); } return [ 'ok' => true, 'search_term' => $term, 'count' => count($results), 'results' => $results ]; } /* |-------------------------------------------------------------------------- | SONDERFALL 3: Kennel Attribut |-------------------------------------------------------------------------- */ if ( strlen($term) >= 3 ) { $kennel_query = new WP_Query([ 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => 8, 'tax_query' => [ [ 'taxonomy' => 'pa_kennel', 'field' => 'slug', 'terms' => sanitize_title($term), ] ] ]); foreach ($kennel_query->posts as $post) { $results[] = $this->format_result( $post ); } if ( ! empty($results) ) { return [ 'ok' => true, 'search_term' => $term, 'count' => count($results), 'results' => $results ]; } }
Der Verein übernimmt keine Gewähr für in der Galerie beschriebene Eigenschaften der Hunde. Weder für charakterliche und rassebedingte Eigenschaften noch im Hinblick auf Gesundheit, Altersangabe, Geschlecht, Größe und Kastrationstatus.