0

I am trying to learn WP Query but finding it a little hard going. I have Posts created from a Forum Plugin (wps_forum_post) and I wish to display counts in descending order based on their selected category (wps_forum_post .meta.wps_fe_brand-retailer-service) and within that three more counts from a further selection (wps_forum_post .meta.wps_fe_overall-experience). I can not seem to be able to get my head around how to do this.

I want to display the results similar to this:

Brand B Posts (Total 32) - POSITIVE (10) INDIFFERENT (12) NEGATIVE (10)
Brand C Posts (Total 28) - POSITIVE (8) INDIFFERENT (10) NEGATIVE (10)
Brand A Posts (Total 26) - POSITIVE (10) INDIFFERENT (10) NEGATIVE (6)

1 Answer 1

0

0 down vote accepted

I think it would help you to read this => http://wordpress.org/support/topic//display-number-of-posts-per-category

function number_postpercat($idcat) {
    global $wpdb;
    $query = "SELECT count FROM $wpdb->term_taxonomy WHERE term_id = $idcat";
    $num = $wpdb->get_col($query);
    echo $num[0];

}
3
  • It's not a very good idea to write SQL in this manner. Also it would be much nicer, if you used get_var instead of get_col since you gen only one value... And I don't think your function solves the problem. All you get is count of posts for given term, not the list of terms sorted by count of posts... May 16, 2018 at 13:30
  • That's a very elegant solution and thank you. I just have to work out now how to ally this to the custom Forum Post Category which is not a Wordpress Category and to work out the overall Category descending order.
    – Colin
    May 16, 2018 at 13:40
  • Krzysiek thank you also yes not a complete solution but at least I am beginning to see a way.
    – Colin
    May 16, 2018 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.