Advertisement
Guest User

author+category

a guest
May 11th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2. $author = get_the_author_meta('id'); // Queried by name // Queried by ID
  3. $categories = $wpdb->get_results("
  4. SELECT DISTINCT(terms.term_id) as ID, terms.name, terms.slug
  5. FROM $wpdb->posts as posts
  6. LEFT JOIN $wpdb->term_relationships as relationships ON posts.ID = relationships.object_ID
  7. LEFT JOIN $wpdb->term_taxonomy as tax ON relationships.term_taxonomy_id = tax.term_taxonomy_id
  8. LEFT JOIN $wpdb->terms as terms ON tax.term_id = terms.term_id
  9. WHERE 1=1 AND (
  10. posts.post_status = 'publish' AND
  11. posts.post_author = '$author' AND
  12. tax.taxonomy = 'category' )
  13. ORDER BY terms.name ASC
  14. ");
  15. ?>
  16.  
  17. <ul>
  18. <?php foreach($categories as $category) : ?>
  19. <li>
  20. <a href="<?php echo get_category_link( $category->ID ); ?>" title="<?php echo $category->name ?>"><?php echo $category->name ?></a>
  21. </li>
  22. <?php endforeach; ?>
  23. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement