您可以从DB中选择此term\\u id,并在SQL查询中添加行号列,然后可以计算它应该位于哪个页面。
例如:
global $wpdb;
$wanted_term = $wpdb->get_row("SELECT terms.* FROM (
SELECT @rownum := @rownum + 1 AS rownum, t.*, tt.taxonomy
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id, (SELECT @rownum := 0) AS r
WHERE tt.taxonomy IN (\'hello\') /* replace taxonomy */
) AS terms WHERE terms.term_id=123 /* replace term_id */ ORDER BY terms.name ASC");
并使用PHP进行计算。
$terms_per_page = 10;
$term_in_page = ceil($wanted_term->rownum / $terms_per_page);
更新SQL查询,使其具有元键、object\\u id和按元值排序
SELECT allterms.* FROM (
SELECT @rownum := @rownum + 1 AS rownum, terms.* FROM (
SELECT DISTINCT t.*, tt.taxonomy, tt.term_taxonomy_id, tm.meta_key, tm.meta_value, tr.object_id
FROM wp_terms AS t
INNER JOIN wp_termmeta AS tm ON ( t.term_id = tm.term_id )
INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy IN (\'fn_release\') /* replace taxonomy */
AND tr.object_id IN (108) /* replace object_ids */
AND ( tm.meta_key = \'ma_tsms\' )
ORDER BY tm.meta_value+0 DESC
) AS terms, (SELECT @rownum := 0) AS r
) AS allterms WHERE allterms.term_id=2543 /* replace term_id */
查询耗时0.0020秒。