Support » Theme: Coraline » Loop for custom post type

  • All my post types show based on the date, newest first.

    But there is one CPT that I am trying to show in the order of comment_count. I have been on this for the past few days now and I have had no luck.

    For example, when I go into a custom taxonomy ‘recom_cats’ I want all the CPT’s under that Taxonomy to show up in order of comment count DESC. Can someone please give me a hand with this or a push in the right direction?

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • Not sure if this would work, but it doesn’t hurt to try (change my_taxonomy_slug to yours).

    function mytheme_special_tax( $query ) {
    	if( $query->is_tax( 'my_taxonomy_slug' ) && $query->is_main_query() && !is_admin() ) {
    		$query->set( 'orderby', 'comment_count' );
    		$query->set( 'order', 'DESC' );
    add_action( 'pre_get_posts', 'mytheme_special_tax' );
Viewing 1 replies (of 1 total)
  • The topic ‘Loop for custom post type’ is closed to new replies.