A
A
art_y102020-06-10 11:02:33
MySQL
art_y10, 2020-06-10 11:02:33

Why is wordpress not showing all search results (when querying MySQL they are), encoding?

Did a custom taxonomy search. I have this 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 set one word in the search (which is obviously in the names of taxonomies) - shows the results. I ask another (which is also there) - it does not show results.
At the same time, if I run the request directly in the database - the results that vorpress does not show, after the request to the database phpmyadmin shows.

Table encoding utf8mb4_unicode_520_ci.
In wordpress config:
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', 'utf8mb4_unicode_520_ci' ); - /* тут пробовал и пустое значение - все равно показывает не все результаты поиска*/


The encoding in html pages is simply utf-8. I know that from a certain version, the wordpress database encoding should be utf8mb4_unicode_520_ci. What does he not like, where to look?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question