通常,pre\\u get\\u post不会更改wordpress视图post计数。您必须调用另一个过滤器挂钩才能更改为count。
add_action(\'pre_get_posts\', function ($query) {
global $pagenow;
if (isset($query->query_vars[\'post_type\'])) {
if ($query->query_vars[\'post_type\'] == \'shop_order\' && (\'edit.php\' == $pagenow)) {
if (!$query->is_main_query()) {
return;
}
// I manipulate $query here
// Get Post Count Here For Each Status
add_filter( \'views_edit-shop_order\', function( $views ) {
$views[\'all\'] = sprintf("<a href=\'%s\'>All (%d)", $url_to_redirect, $all_count );
$views[\'wc-processing\'] = sprintf("<a href=\'%s\'>Processing (%d)", $url_to_redirect, $processing_count );
$views[\'wc-completed\'] = sprintf("<a href=\'%s\'>Completed (%d)", $url_to_redirect, $completed_count );
$views[\'wc-failed\'] = sprintf("<a href=\'%s\'>Failed (%d)", $url_to_redirect, $failed_count );
return $views;
// Sample array we get print_r( $views )
Array
(
[all] => All (24)
[wc-processing] => Processing (3)
[wc-completed] => Completed (19)
[wc-failed] => Failed (2)
)
});
}
}
}, 1000, 1);