gpt4 book ai didi

php - 为什么我的 WordPress 类别列表会显示草稿和垃圾数量?

转载 作者:行者123 更新时间:2023-11-29 13:31:11 25 4
gpt4 key购买 nike

我使用这段代码来显示特定分类中的类别列表,以及该类别中的帖子数量。

每当我删除帖子时,帖子计数仍包括已删除的帖子并显示类别标题,这也适用于已放入草稿的帖子。直到我永久删除帖子后,类别和/或计数才会消失。

我错过了什么?

<?php $args = array(
'show_option_all' => '',
'orderby' => 'slug',
'order' => 'ASC',
'style' => 'list',
'show_count' => 1,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => '',
'feed_type' => '',
'feed_image' => '',
'exclude' => '',
'exclude_tree' => '',
'include' => '',
'hierarchical' => 1,
'title_li' => __( '' ),
'show_option_none' => __('No categories'),
'number' => null,
'echo' => 0,
'depth' => 0,
'current_category' => 0,
'pad_counts' => 0,
'taxonomy' => 'artists',
'walker' => null
);
$variable = wp_list_categories($args);
$variable = preg_replace('/\<\/a\> \((.*)\)/',' <span class="quantity">$1</span></a>',$variable);


echo $variable;?>

最佳答案

我做了一些谷歌搜索,在 WordPress 表单上,我发现了这段代码,将其放入我的functions.php 文件中,虽然它似乎不允许我快速编辑,但它确实修复了帖子计数问题...

// Function that helps the post count
add_action('edited_term_taxonomy','yoursite_edited_term_taxonomy',10,2);
function yoursite_edited_term_taxonomy($term,$taxonomy) {
global $wpdb,$post;
//in quick edit mode, $post is an array()
//in full edit mode $post is an object
if ( is_array( $post ))
$posttype=$post['post_type'];
else
$posttype=$post->post_type;
if ($posttype) {
$DB_prefix=$wpdb->get_blog_prefix(BLOG_ID_CURRENT_SITE);
$sql = "UPDATE ".$DB_prefix."term_taxonomy tt
SET count =
(SELECT count(p.ID) FROM ".$DB_prefix."term_relationships tr
LEFT JOIN ".$DB_prefix."posts p
ON (p.ID = tr.object_id AND p.post_type = '".$posttype."' AND p.post_status = 'publish')
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy = '".$taxonomy->name."'
";
$wpdb->query($sql);
}
}

希望我能解释一下,但我对 PHP 很陌生......

关于php - 为什么我的 WordPress 类别列表会显示草稿和垃圾数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19436541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com