Answer the question
In order to leave comments, you need to log in
How to output custom taxonomy (category) for custom post types?
Hello!
For one topic, I created a custom post type - teacher, as well as a custom taxonomy teacher_category.
But I can't display the category page through archive.php. Tell me how to make a selection using WP_Query?
If there is little information, please ask clarifying questions.
Answer the question
In order to leave comments, you need to log in
for this you need to create a file taxonomy-teacher_category.php
It worked! Thank you very much. You helped me a lot!
PS By default, only the last 2 posts from the category were displayed. Solved it via query_posts()
<?php global $query_string;
$posts = query_posts($query_string.'&posts_per_page=10'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
/*Содержимое страницы*/
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
$query = new WP_Query (
'category_name = teacher_category',
'meta_key = teacher'
);
@zelenin , I created a normal category.php and the standard categories are working.
Next, I made a duplicate of this file and called it taxonomy-teacher_category.php
But when I try to go to the category page at the custom category address (example site.ru/teacher_category/atlanta ), I get an error 404: Page not found.
Can you help me figure out where the problem might be?
PS I'm attaching a taxonomy registration code listing. If you need additional information - I will provide.
function my_taxonomies_teacher() {
$labels = array(
'name' => _x( 'Teacher Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Teacher Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Teacher Categories' ),
'all_items' => __( 'All Teacher Categories' ),
'parent_item' => __( 'Parent Teacher Category' ),
'parent_item_colon' => __( 'Parent Teacher Category:' ),
'edit_item' => __( 'Edit Teacher Category' ),
'update_item' => __( 'Update Teacher Category' ),
'add_new_item' => __( 'Add New Teacher Category' ),
'new_item_name' => __( 'New teacher Category' ),
'menu_name' => __( 'Teacher Categories' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy( 'teacher_category', 'teacher', $args );
}
add_action( 'init', 'my_taxonomies_teacher', 0 );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question