Как отобразить все запросы к базе данных, сделанные Wordpress?

Функция:

public float simpleSimilarity(String u, String v) {
    String[] a = u.split(" ");
    String[] b = v.split(" ");

    long correct = 0;
    int minLen = Math.min(a.length, b.length);

    for (int i = 0; i < minLen; i++) {
        String aa = a[i];
        String bb = b[i];
        int minWordLength = Math.min(aa.length(), bb.length());

        for (int j = 0; j < minWordLength; j++) {
            if (aa.charAt(j) == bb.charAt(j)) {
                correct++;
            }
        }
    }

    return (float) (((double) correct) / Math.max(u.length(), v.length()));
}

Тест:

String a = "This is the first string.";

String b = "this is not 1st string!";

// for exact string comparison, use .equals

boolean exact = a.equals(b);

// For similarity check, there are libraries for this
// Here I'll try a simple example I wrote

float similarity = simple_similarity(a,b);
13
задан Community 23 May 2017 в 12:01
поделиться

2 ответа

Если вы добавите , определите ('SAVEQUERIES', true) в файл конфигурации, затем вы можете перечислить все запросы, сделанные для текущей страницы, добавив следующее в свою тему.

if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    print_r($wpdb->queries);
    echo "</pre>";
}

Подробнее см. В документации: http://codex.wordpress.org/Editing_wp-config.php#Save_queries_for_analysis

43
ответ дан 1 December 2019 в 00:20
поделиться

или вы можете подключиться к posts_request. Вы можете поместить coe внутри functions.php, например

add_filter('posts_request','debug_post_request'); // debugging sql query of a post

function debug_post_request($sql_text) {

   $GLOBALS['debugku'] = $sql_text; //intercept and store the sql<br/>
   return $sql_text; 

}

в футере вашей темы, вы можете использовать print_r, например

print_r($GLOBALS['debugku']);
5
ответ дан 1 December 2019 в 00:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: