显示作者的自定义帖子计数,而不是默认帖子

时间:2013-03-08 作者:lu Ga lay

<?php    
global $wp_query;    
$curauth = $wp_query->get_queried_object();    
$post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = \'" . $curauth->ID . "\' AND post_type =     photoshop_tutorial\' AND post_status = \'publish\'");    
?>

<p>Post Count: <?php echo $post_count; ?></p>
我已尝试使用此代码(&P);它显示了整个photoshop_tutorial 帖子很重要,但我想为每个作者的帖子显示,因为我想将其添加到作者页面中。

例如:

史密斯发布<?php $post_count; ?> photoshop教程

我该怎么做?

1 个回复
SO网友:Mike Madern

您是否尝试使用获取请求的帖子WP_Query?

$posts = new WP_Query();
$posts->query( array(
    \'posts_per_page\' => -1,
    \'author\' => $curauth->ID,
    \'post_type\' => \'photoshop_tutorial\'
) );

$post_count = sizeof( $posts->posts );

结束

相关推荐

post_count not working

我已经解决了最初的问题,但我想知道我做错了什么。<?php $args = array( \'post_type\' => \'page\', \'post__not_in\' => array( $post->ID ), \'post_parent\' => \'43\', \'post_count\' => \'3\', );