我如何列出当前作者的类别?

时间:2013-01-15 作者:Genxer

我的代码让作者写文章类别,但只有2个ID有作者列表类别。。I替换$current_user->ID 但它没有起作用。

<?php
    $categories = $wpdb->get_results("
        SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
        FROM $wpdb->posts as posts
        LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
        LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
        LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
        WHERE 1=1 AND (
            posts.post_status = \'publish\' AND
            posts.post_author = \'2\' AND
            tax.taxonomy = \'category\' )
        ORDER BY terms.name ASC
    ");
    ?>
    <ul>
        <?php foreach($categories as $category) : ?>
        <li>
            <a href="<?php echo get_category_link( $category->ID ); ?>" title="<?php echo $category->name ?>"><?php echo $category->name ?></a>
        </li>
        <?php endforeach; ?>
    </ul> 

1 个回复
最合适的回答,由SO网友:Reigel 整理而成

试试这样。。。

你需要先打电话global $post;

然后获取作者id$author_id = $post->post_author;

结束

相关推荐

problems exluding categories

我以前做过,但由于某种原因,它不起作用,我也不知道为什么。我只是想从博客页面中排除一些类别。我以为这件事很简单。我有索引。php文件打开,在循环之前,我这样做了 query_posts( $guery_string . \'&cat=-6\' ) if (have_posts)......rest of loop here. 我甚至尝试添加全局$query\\u字符串;最重要的是,我所做的一切都不能摆脱第6类。这种方法在最新版本的wordpress中是否不再有效?