L
L
Lukin Danil2020-08-04 20:42:24
WordPress
Lukin Danil, 2020-08-04 20:42:24

Why is none of them displayed when displaying user posts by category?

In functions.php I register a custom post type and taxonomy:

add_action('init', 'doors_post_type');
function doors_post_type(){
  register_taxonomy('category_door', array('doors'), array(
    'label'                 => 'Категории', // определяется параметром $labels->name
    'labels'                => array(
      'name'              => 'Категории',
      'singular_name'     => 'Категория',
      'search_items'      => 'Искать Категории',
      'all_items'         => 'Все категории',
      'parent_item'       => 'Родит. Категория',
      'parent_item_colon' => 'Родит. Категория:',
      'edit_item'         => 'Ред. Категории',
      'update_item'       => 'Обновить Категории',
      'add_new_item'      => 'Добавить Категорию',
      'new_item_name'     => 'Новая категория',
      'menu_name'         => 'Категория',
    ),
    'description'           => 'Категории дверей', // описание таксономии
    'public'                => true,
    'show_in_nav_menus'     => false, // равен аргументу public
    'show_ui'               => true, // равен аргументу public
    'show_tagcloud'         => true, // равен аргументу show_ui
    'hierarchical'          => true,
    'rewrite'               => array('slug'=>'doors', 'hierarchical'=>false, 'with_front'=>false, 'feed'=>false ),
    'show_admin_column'     => true, // Позволить или нет авто-создание колонки таксономии в таблице ассоциированного типа записи. (с версии 3.5)
  ) );


  register_post_type('doors', array(
    'labels'             => array(
      'name'               => 'Двери', // Основное название типа записи
      'singular_name'      => 'Дверь', // отдельное название записи типа Book
      'add_new'            => 'Добавить новую',
      'add_new_item'       => 'Добавить новую дверь',
      'edit_item'          => 'Редактировать дверь',
      'new_item'           => 'Новая дверь',
      'view_item'          => 'Посмотреть дверь',
      'search_items'       => 'Найти дверь',
      'not_found'          =>  'Дверей не найдено',
      'not_found_in_trash' => 'В корзине дверей не найдено',
      'parent_item_colon'  => '',
      'menu_name'          => 'Двери'

    ),
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => true,
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'menu_icon'          => 'dashicons-smartphone',
    'supports'           => array('title','editor')
  ) );
}


Then, through the shortcode, I display it on the page I need
add_shortcode( 'shortcode_doors', 'generate_doors_new' );

function generate_doors_new () {
  $articles = new WP_Query('post_type=doors&category_name=noce');
  ?>
  <div class="row">
    <? while ($articles -> have_posts()):$articles -> the_post(); ?>

      <div class="col-3 door_wrap">
        <img src="<?php the_field('door_image', $post); ?>" alt="">
        <!-- <p><?php //the_field('door_header', $post); ?></p> -->
        <p><?php the_title(); ?></p>
      </div>

    <? endwhile; wp_reset_postdata(); ?>
  </div>
  <?
}


the label of the desired category is called "noce", I tried it by ID through cat = 2, it also does not display anything, if you remove the category from the request, then everything displays.
help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
its2easyy, 2020-08-04
@ld161100

category_name=nocesearches in default categories, and to search by your taxonomy you need to build a query with your category_door taxonomy https://wp-kama.ru/function/wp_query#taxonomies .
In theory it should work withcategory_door=noce

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question