wordpress源碼讀研之困惑:If no taxonomy, assume tt_ids

來源:互聯網
上載者:User
在下讀wordpress源碼,頗多收穫。下面函數裡,"If no taxonomy, assume tt_ids"為何意?矛盾吧?既為空白,哪來的 term_id ?可以假定嗎?既為空白,如何從表 term_taxonomy 中選擇?
請高手指點一二為盼。
/**
* Will remove all of the term ids from the cache.
*
* @since 2.3.0
* @uses $wpdb
*
* @param int|array $ids Single or list of Term IDs
* @param string $taxonomy Can be empty and will assume tt_ids, else will use for context.
* @param bool $clean_taxonomy Whether to clean taxonomy wide caches (true), or just individual term object caches (false). Default is true.
*/
function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
global $wpdb;

if ( !is_array($ids) )
$ids = array($ids);

$taxonomies = array();
// If no taxonomy, assume tt_ids.
if ( empty($taxonomy) ) {
$tt_ids = array_map('intval', $ids);
$tt_ids = implode(', ', $tt_ids);
$terms = $wpdb->get_results(" SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE
term_taxonomy_id IN ($tt_ids)");
$ids = array();
foreach ( (array) $terms as $term ) {
$taxonomies[] = $term->taxonomy;
$ids[] = $term->term_id;
wp_cache_delete($term->term_id, $term->taxonomy);
}
$taxonomies = array_unique($taxonomies);
} else {
$taxonomies = array($taxonomy);
foreach ( $taxonomies as $taxonomy ) {
foreach ( $ids as $id ) {
wp_cache_delete($id, $taxonomy);
}
}
}

foreach ( $taxonomies as $taxonomy ) {
if ( $clean_taxonomy ) {
wp_cache_delete('all_ids', $taxonomy);
wp_cache_delete('get', $taxonomy);
delete_option("{$taxonomy}_children");
// Regenerate {$taxonomy}_children
_get_term_hierarchy($taxonomy);
}

/**
* Fires once after each taxonomy's term cache has been cleaned.
*
* @since 2.5.0
*
* @param array $ids An array of term IDs.
* @param string $taxonomy Taxonomy slug.
*/
do_action( 'clean_term_cache', $ids, $taxonomy );
}

wp_cache_set( 'last_changed', microtime(), 'terms' );
}


回複討論(解決方案)

If no taxonomy, assume tt_ids--如果參數 taxonomy 為空白的話,我們就假定 參數 id 是 tt_ids ----term_taxonomy 表的
term_taxonomy_id .否則,視為 term_id.

如果 $taxonomy(分類名稱)為空白
則取 $ids(分類號)對應的分類名

因為後面的檢索中是以分類名為基準的

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.