• I did a search on custom taxonomy. I have the following code:

    
    <?php 
    $search_term = explode( ' ', get_search_query( false ) );
    global $wpdb;
    
        $select = "
        SELECT DISTINCT t.*, tt.*
        FROM wp_terms AS t
        LEFT JOIN wp_term_taxonomy AS tt
        ON t.term_id = tt.term_id
        LEFT JOIN wp_termmeta AS tm
        ON t.term_id = tm.term_id
        WHERE tt.taxonomy IN ('customtaxonomyname')";
        $first = true;
    
        foreach ( $search_term as $s ){
          if ( $first ){
            $select .= " AND (t.name LIKE '%s')";
            $string_replace[] = '%'.$wpdb->esc_like( $s ).'%';
            $first = false;
          /*}else{
            $select .= " OR (t.name LIKE '%s') OR (tm.meta_value LIKE '%s')";
            $string_replace[] = '%'. $wpdb->esc_like( $s ).'%';*/
          }
        }
        $select .= " ORDER BY t.name ASC";
        $terms = $wpdb->get_results( $wpdb->prepare( $select, $string_replace ) );
    
        if ( count($terms) > 0 ){
          foreach ( $terms as $term ) {
            if ($term->taxonomy == 'customtaxonomyname') {
            //var_dump($search_term);
            echo '<article id="post-" class="attachment type-attachment status-inherit hentry">';
            echo '<header class="entry-header"><h2 class="entry-title"><a href="'.esc_url( get_term_link( $term ) ).'" title="'.esc_attr( $term->name ).'" rel="bookmark">' . esc_html( $term->name ) . '</a></h2><div class="entry-meta"></div></header>';
            echo '<div class="entry-summary"></div><footer class="entry-footer"></footer></article>';
            }
          }
    
        } ?>
    

    If I enter one word in the search (which is in the names of taxonomies) – the search shows the results. I enter another word (which is also in the names of taxonomies) – the search does not show results. At the same time, if I make a query to the database in phpmyadmin – the results that WordPress does not show, I see in phpmyadmin.

    Table encoding utf8mb4_unicode_520_ci. In the WordPress config:

    
    define( 'DB_CHARSET', 'utf8mb4' );
    
    /** The Database Collate type. Don't change this if in doubt. */
    define( 'DB_COLLATE', 'utf8mb4_unicode_520_ci' ); - /* Here I try to use empty value - anyway, I don’t see all the search results in the frontend of WordPress for some names of taxonomies*/
    

    The encoding in the html pages is just utf-8. I know that from a certain version the encoding of the WordPress database should be utf8mb4_unicode_520_ci.

    How I can resolve this problem?

    • This topic was modified 4 years, 5 months ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Why does wordpress not show all search results (when querying in MySQL they are)’ is closed to new replies.