Group & Sort Taxonomy terms by letter – Is there a better way?

Here is the way I did it, add_action(‘the_content’, ‘lm_alpha_order’); function lm_alpha_order($content){ if(is_page(‘alphabetique’)){ $args = array( ‘taxonomy’ => ‘media_tag’, ‘hide_empty’ => true, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ); $terms = get_terms(‘media_tag’, $args); $azRange = range(‘A’, ‘Z’); echo ‘<div class=”half left” style=”float:left;padding-left: 2em;”>’; foreach ($azRange as $letter) { $letter_outputs=””; $the_letter =false; //print(“$letter\n”); $count = 0; $ul=”<ul … Read more

Custom post type category archive URL redirects to home page

Change ‘public’ => false, to ‘public’ => true, when using register_taxonomy(). Also, don’t use capital letters for the post type name in register_post_type(). Here’s the full updated code (make sure to save permalinks after updating your code): add_action( ‘init’, ‘create_project_taxonomies’, 0 ); add_action( ‘init’, ‘create_posttype’ ); function create_posttype() { $args = array( ‘labels’ => array(‘name’=>__(‘Projects’), … Read more

Custom taxonomy term links out of order

Use wp_list_categories() instead, which handles the display and ordering of hierarchical terms. Despite its name suggesting that it’s just for categories, it works with custom taxonomies too: $taxonomy_args = array( ‘public’ => true, ‘_builtin’ => false, ); $output=”names”; $operator=”and”; $taxonomies = get_taxonomies( $taxonomy_args, $output, $operator ); if ( $taxonomies ) { foreach ( $taxonomies as … Read more

How to show one post content in another post content which has same terms?

I have solved the problem myself: What I did is: First created single-football_league.php template where i placed following codes: <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( ‘content-parts/content’, ‘league’ ); ?> <?php endwhile; ?> Second: In content-league.php, I placed following codes, and it works: $terms = wp_get_post_terms( $post->ID, array(‘competition’, ‘session’) ); $term_slugs = … Read more

How to show post which has the specific taxonomy terms?

Use this code instead. $terms = wp_get_post_terms( $post->ID, array(‘competition’, ‘session’) ); $term_slugs = wp_list_pluck( $terms, ‘slug’ ); $season = wp_get_post_terms( $post->ID, ‘session’ ); $season_slugs = wp_list_pluck( $terms, ‘slug’ ); $args = array( ‘post_type’ => array( ‘football_fixture’ ), // profile and letter are CPTs ‘tax_query’ => array( array( ‘taxonomy’ => ‘competition’, ‘field’ => ‘slug’, ‘terms’ => … Read more