Counting number of posts in a category and its sub categories and displaying result using shortcode

The shortcode // Add Shortcode to show posts count inside a category function category_post_count( $atts ) { $atts = shortcode_atts( array( ‘category’ => null ), $atts ); // get the category by slug. $term = get_term_by( ‘slug’, $atts[‘category’], ‘category’); return ( isset( $term->count ) ) ? $term->count : 0; } add_shortcode( ‘category_post_count’, ‘category_post_count’ ); Usage … Read more

Get current term’s ID

Here is a function I use to list subterms: /** * Lists all subentries of a taxonomy. * * @return void */ function ttt_get_subterms( $args = array () ) { if ( ! isset ( get_queried_object()->taxonomy ) ) { return; } $options = array ( ‘child_of’ => get_queried_object_id() , ‘echo’ => 0 , ‘taxonomy’ => … Read more

Sort posts by number of matched terms

Well the only way i can think of is to create an two dimentions array of the results you want to output, and the number of matching tags. so for example: $results = array(); $searched_tags = $_post[‘my_tax’]; $searched_tags = explode(“+”, $searched_tags); while (have_posts()){ $the_post(); $result[‘r’] = ‘<div class=”post”> <div class=”title”><h2><a href=”‘.get_permalink($post->ID).'” title=”‘.get_the_title($post->ID).'”>’.get_the_title($post->ID).'</a></h2></div> <div class=”excerpt”>’.get_the_excerpt().'</div> </div>’; … Read more

List taxonomies with thumbnails

How to get the data back When you look at your code, then you got get_option( “taxonomy_{$t_id}” ) in it, which actually calls the value from the DB options table. So you should simply replace the $t_id with your actual term id. The term ID can be retrieved via get_query_var( ‘tag_id’ ) for Tags on … Read more