Custom post type taxonomy template and URL confusion
Custom post type taxonomy template and URL confusion
Custom post type taxonomy template and URL confusion
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
You can use WordPress function get_objects_in_term $users = get_objects_in_term(2, ‘user_category’); // 2 being term id This return array of users that have this same term id.
Associate custom CPT with another CPT’s taxonomy and rewrite permalinks
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
If you’d like to include the post post type, it needs to be added to the post_type parameter for WP_Query: $args = array(‘post_type’ => array( ‘post’, ‘resources’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘resource’, ‘field’ => ‘slug’, ‘terms’ => $custom_term->slug, ), ), );
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
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
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
I have realised the problem isn’t with the code I have posted and the issue is when the taxonomies are being created. Basically the reason this wasn’t working is because the query_var parameter was set to false when registering the taxonomy. I changed this to true and my filtering started working.