我已指定一个名为Highlight
我在帖子中添加了一个名为Featured
.
每当我想为一篇文章添加特色时,我只需将其分配给特色。
对于每个作者,我想显示他们的特色帖子总数。
那么函数the_author_posts()
将显示帖子总数。我想显示作者收到的帖子总数。
我该怎么做?
我已指定一个名为Highlight
我在帖子中添加了一个名为Featured
.
每当我想为一篇文章添加特色时,我只需将其分配给特色。
对于每个作者,我想显示他们的特色帖子总数。
那么函数the_author_posts()
将显示帖子总数。我想显示作者收到的帖子总数。
我该怎么做?
/**
* Get the author post count for a tax query.
*
* @link http://wordpress.stackexchange.com/q/159160/1685
*
* @param array $tax_query
* @return int
*/
function wpse_159160_get_author_posts_by_tax( $tax_query ) {
global $wpdb;
$where = get_posts_by_author_sql( \'post\', true, get_post()->post_author );
$tax_query = new WP_Tax_Query( $tax_query );
$sql = $tax_query->get_sql( $wpdb->posts, \'ID\' );
return ( int ) $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts {$sql[\'join\']} $where {$sql[\'where\']}" );
}
使用中:$count = wpse_159160_get_author_posts_by_tax(
array(
array(
\'taxonomy\' => \'highlight\',
\'terms\' => \'featured\',
\'field\' => \'slug\',
)
)
);
echo "$count Featured Posts";
如果希望减少对函数的控制(&;neater模板代码),可以硬编码$tax_query
函数中的参数,只需调用它而不在其他地方使用参数。我正在尝试创建标题为1, 2 等$published_posts = wp_count_posts(\'orders\')->publish; $count = $published_posts + $a; $success = get_page_link(794); if(wp_mail($admin_email, \'Заказ с сайта: \'.get_bloginfo(\'name\'), $message)) { $my_p