Want more features on Pastebin? Sign Up, it's FREE!
Guest

Count several custom post_types of an specific author in Aut

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 1.00 KB  |  views: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. //first post_type
  3. global $wp_query;
  4. $curauth = $wp_query->get_queried_object();
  5. $post_count_emp = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth->ID . "' AND post_type = 'listing' AND post_status = 'publish'");
  6. ?>
  7. <?php
  8. //second post_type
  9. global $wp_query;
  10. $curauth = $wp_query->get_queried_object();
  11. $post_count_pos = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth->ID . "' AND post_type = 'post' AND post_status = 'publish'");
  12. ?>
  13. <?php
  14. //third post_type
  15. global $wp_query;
  16. $curauth = $wp_query->get_queried_object();
  17. $post_count_ques = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth->ID . "' AND post_type = 'question' AND post_status = 'publish'");
  18. ?>
  19.  
  20. <h2>The Author published:</h2>
  21.         <ul>
  22.     <li> <?php echo $post_count_emp; ?>  Listing (s) </li>
  23.     <li> <?php echo $post_count_pos; ?>  Post (s) </li>
  24.     <li> <?php echo $post_count_ques; ?>  Question (s) </li>
  25.     </ul>
clone this paste RAW Paste Data