How can i list current author’s categories?

My Code getting authors written post categories but just 2 ID has author lists category.. I replace $current_user->ID but it is not worked.

<?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="https://wordpress.stackexchange.com/questions/81599/<?php echo get_category_link( $category->ID ); ?>" title="<?php echo $category->name ?>"><?php echo $category->name ?></a>
        </li>
        <?php endforeach; ?>
    </ul> 

1 Answer
1

try something like this…

you need to first call global $post;

then get the author id like $author_id = $post->post_author;

Leave a Comment