WordPress как на ладони

Проблемы с выводом произвольных категорий произвольных типов записей не могу вывести категории по ID записи

Помогите решить вопрос с категориями.
мне нужно получать категорию по id произвольного типа поста(товара)
я создал произвольную таксономию (Категория товара) для товаров и создал произвольный тип записей(Товары).

пытаюсь в шаблоне получить категорию с помощью функции

<?php

	$category = get_the_category(166); 
	echo '<pre'.'>';
		print_r($category);
	echo '</pre'.'>';
?>

**Выводит пустой массив sad
Почему ? SOS :c

может я что-то пропустил ?
какую нибудь фунцию там которая привязывает тип записи с таксономией ?.
Жду ваших советов и замечанийmosking

регистрация произвольной категории**

<?php 
add_action( 'init', 'create_taxonomy' );
function create_taxonomy(){
	// список параметров: http://wp-kama.ru/function/get_taxonomy_labels
	register_taxonomy('category_goods', array('goods_post_type'), array(
		'label'                 => 'Категория товара', // определяется параметром $labels->name
		'labels'                => array(
			'name'              => 'Категория',
			'singular_name'     => 'Категория товара',
			'search_items'      => 'Поиск категорий товара',
			'all_items'         => 'Все категории товаров',
			'view_item '        => 'Показать категорию товара',
			'parent_item'       => 'Родительская',
			'parent_item_colon' => 'Родительская',
			'edit_item'         => 'Редактировать категорию товара',
			'update_item'       => 'Обновить категорию товара',
			'add_new_item'      => 'Добавить новую категорию товара',
			'new_item_name'     => 'Новое имя Категории товара',
			'menu_name'         => 'Категории товаров',
		),
		'description'           => '', // описание таксономии
		'public'                => true,
		'publicly_queryable'    => null, // равен аргументу public
		'show_in_nav_menus'     => true, // равен аргументу public
		'show_ui'               => true, // равен аргументу public
		'show_in_menu'          => true, // равен аргументу show_ui
		'show_tagcloud'         => true, // равен аргументу show_ui
		'show_in_rest'          => null, // добавить в REST API
		'slug'                  => 'goods',
		'rest_base'             => null, // $taxonomy
		'hierarchical'          => true,
		//'update_count_callback' => '_update_post_term_count',
		'rewrite'               => true,
		'query_var'             => $goods_taxonomy, // название параметра запроса
		'capabilities'          => array(),
		'meta_box_cb'           => null, // callback функция. Отвечает за html код метабокса (с версии 3.8): post_categories_meta_box или post_tags_meta_box. Если указать false, то метабокс будет отключен вообще
		'show_admin_column'     => false, // Позволить или нет авто-создание колонки таксономии в таблице ассоциированного типа записи. (с версии 3.5)
		'_builtin'              => false,
		'show_in_quick_edit'    => null, // по умолчанию значение show_ui
	) );
}

add_action('init','good_cat_for_goods');
function good_cat_for_goods(){
	register_taxonomy_for_object_type('category_goods','good_cat_for_goods');
}
?>

вот регистрация произвольных типов записей

<?php

add_action( 'init', 'register_post_types' );
function register_post_types(){
	register_post_type('goods_post_type', array(
		'label'  => null,
		'labels' => array(
			'name'               => 'Товары', // основное название для типа записи
			'singular_name'      => 'Товар', // название для одной записи этого типа
			'add_new'            => 'Добавить товар', // для добавления новой записи
			'add_new_item'       => 'Добавление товара', // заголовка у вновь создаваемой записи в админ-панели.
			'edit_item'          => 'Редактирование товара', // для редактирования типа записи
			'new_item'           => 'Новый товар', // текст новой записи
			'view_item'          => 'Смотреть товар', // для просмотра записи этого типа.
			'search_items'       => 'Искать товар', // для поиска по этим типам записи
			'not_found'          => 'Не найдено', // если в результате поиска ничего не было найдено
			'not_found_in_trash' => 'Не найдено в корзине', // если не было найдено в корзине
			'parent_item_colon'  => '', // для родителей (у древовидных типов)
			'menu_name'          => 'Товары', // название меню
		),
		'description'         => '',
		'public'              => true,
		'publicly_queryable'  => true, // зависит от public
		'exclude_from_search' => null, // зависит от public
		'show_ui'             => null, // зависит от public
		'show_in_menu'        => null, // показывать ли в меню адмнки
		'show_in_admin_bar'   => null, // по умолчанию значение show_in_menu
		'show_in_nav_menus'   => null, // зависит от public
		'show_in_rest'        => null, // добавить в REST API. C WP 4.7
		'rest_base'           => null, // $post_type. C WP 4.7
		'menu_position'       => 4,
		'menu_icon'           => 'dashicons-feedback', 
		//'capability_type'   => 'post',
		//'capabilities'      => 'post', // массив дополнительных прав для этого типа записи
		//'map_meta_cap'      => null, // Ставим true чтобы включить дефолтный обработчик специальных прав
		'hierarchical'        => false,
		'supports'            => array('title','editor','thumbnail','excerpt','comments'), // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
		'taxonomies'          => array('category_goods'),
		'has_archive'         => false,
		'rewrite'             => true,
		'query_var'           => true,
	) );
}
?>

я создал категории. я создал товары. связал их(в админке).
но возвращает пустой массив где бывают категории.
SOS :c

вот дебаг массива товаров.
там нет категории. как ее достать ??

WP_Query Object
(
	[query] => Array
		(
			[post_type] => goods_post_type
		)

	[query_vars] => Array
		(
			[post_type] => goods_post_type
			[error] => 
			[m] => 
			[p] => 0
			[post_parent] => 
			[subpost] => 
			[subpost_id] => 
			[attachment] => 
			[attachment_id] => 0
			[name] => 
			[static] => 
			[pagename] => 
			[page_id] => 0
			[second] => 
			[minute] => 
			[hour] => 
			[day] => 0
			[monthnum] => 0
			[year] => 0
			[w] => 0
			[category_name] => 
			[tag] => 
			[cat] => 
			[tag_id] => 
			[author] => 
			[author_name] => 
			[feed] => 
			[tb] => 
			[paged] => 0
			[meta_key] => 
			[meta_value] => 
			[preview] => 
			[s] => 
			[sentence] => 
			[title] => 
			[fields] => 
			[menu_order] => 
			 => 
			[category__in] => Array
				(
				)

			[category__not_in] => Array
				(
				)

			[category__and] => Array
				(
				)

			[post__in] => Array
				(
				)

			[post__not_in] => Array
				(
				)

			[post_name__in] => Array
				(
				)

			[tag__in] => Array
				(
				)

			[tag__not_in] => Array
				(
				)

			[tag__and] => Array
				(
				)

			[tag_slug__in] => Array
				(
				)

			[tag_slug__and] => Array
				(
				)

			[post_parent__in] => Array
				(
				)

			[post_parent__not_in] => Array
				(
				)

			[author__in] => Array
				(
				)

			[author__not_in] => Array
				(
				)

			[ignore_sticky_posts] => 
			[suppress_filters] => 
			[cache_results] => 1
			[update_post_term_cache] => 1
			[lazy_load_term_meta] => 1
			[update_post_meta_cache] => 1
			[posts_per_page] => 10
			[nopaging] => 
			[comments_per_page] => 50
			[no_found_rows] => 
			[order] => DESC
		)

	[tax_query] => WP_Tax_Query Object
		(
			[queries] => Array
				(
				)

			[relation] => AND
			[table_aliases:protected] => Array
				(
				)

			[queried_terms] => Array
				(
				)

			[primary_table] => wp_posts
			[primary_id_column] => ID
		)

	[meta_query] => WP_Meta_Query Object
		(
			[queries] => Array
				(
				)

			[relation] => 
			[meta_table] => 
			[meta_id_column] => 
			[primary_table] => 
			[primary_id_column] => 
			[table_aliases:protected] => Array
				(
				)

			[clauses:protected] => Array
				(
				)

			[has_or_relation:protected] => 
		)

	[date_query] => 
	[request] => SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'goods_post_type' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')  ORDER BY wp_posts.post_date DESC LIMIT 0, 10
	[posts] => Array
		(
			[0] => WP_Post Object
				(
					[ID] => 167
					[post_author] => 1
					[post_date] => 2019-02-19 17:52:48
					[post_date_gmt] => 2019-02-19 14:52:48
					[post_content] => 
					[post_title] => Блины с картошкой
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => bliny-s-kartoshkoj
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:52:48
					[post_modified_gmt] => 2019-02-19 14:52:48
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=167
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[1] => WP_Post Object
				(
					[ID] => 166
					[post_author] => 1
					[post_date] => 2019-02-19 17:51:34
					[post_date_gmt] => 2019-02-19 14:51:34
					[post_content] => 
					[post_title] => Блины с голландским сыром
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => bliny-s-gollandskim-syrom
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:51:34
					[post_modified_gmt] => 2019-02-19 14:51:34
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=166
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[2] => WP_Post Object
				(
					[ID] => 165
					[post_author] => 1
					[post_date] => 2019-02-19 17:49:36
					[post_date_gmt] => 2019-02-19 14:49:36
					[post_content] => 
					[post_title] => Хинкал чеченский
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => hinkal-chechenskij
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:49:53
					[post_modified_gmt] => 2019-02-19 14:49:53
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=165
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[3] => WP_Post Object
				(
					[ID] => 164
					[post_author] => 1
					[post_date] => 2019-02-19 17:48:23
					[post_date_gmt] => 2019-02-19 14:48:23
					[post_content] => 
					[post_title] => Хинкал слоеный
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => hinkal-sloenyj
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:48:28
					[post_modified_gmt] => 2019-02-19 14:48:28
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=164
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[4] => WP_Post Object
				(
					[ID] => 163
					[post_author] => 1
					[post_date] => 2019-02-19 17:47:11
					[post_date_gmt] => 2019-02-19 14:47:11
					[post_content] => 
					[post_title] => Баклажан маринованный
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => baklazhan-marinovannyj
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:47:25
					[post_modified_gmt] => 2019-02-19 14:47:25
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=163
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[5] => WP_Post Object
				(
					[ID] => 162
					[post_author] => 1
					[post_date] => 2019-02-19 17:43:34
					[post_date_gmt] => 2019-02-19 14:43:34
					[post_content] => 
					[post_title] => Лечо
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => lecho
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:45:00
					[post_modified_gmt] => 2019-02-19 14:45:00
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=162
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[6] => WP_Post Object
				(
					[ID] => 161
					[post_author] => 1
					[post_date] => 2019-02-19 17:42:27
					[post_date_gmt] => 2019-02-19 14:42:27
					[post_content] => 
					[post_title] => Икра овощная
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => ikra-ovoshchnaya
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:42:58
					[post_modified_gmt] => 2019-02-19 14:42:58
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=161
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[7] => WP_Post Object
				(
					[ID] => 160
					[post_author] => 1
					[post_date] => 2019-02-19 17:36:28
					[post_date_gmt] => 2019-02-19 14:36:28
					[post_content] => 
					[post_title] => Варенье малиновое
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => varene-malinovoe
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:36:47
					[post_modified_gmt] => 2019-02-19 14:36:47
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=160
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[8] => WP_Post Object
				(
					[ID] => 159
					[post_author] => 1
					[post_date] => 2019-02-19 17:35:07
					[post_date_gmt] => 2019-02-19 14:35:07
					[post_content] => 
					[post_title] => Варенье кизиловое
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => varene-kizilovoe
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:35:31
					[post_modified_gmt] => 2019-02-19 14:35:31
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=159
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

			[9] => WP_Post Object
				(
					[ID] => 158
					[post_author] => 1
					[post_date] => 2019-02-19 17:33:48
					[post_date_gmt] => 2019-02-19 14:33:48
					[post_content] => 
					[post_title] => Зонтики
					[post_excerpt] => 
					[post_status] => publish
					[comment_status] => open
					[ping_status] => closed
					[post_password] => 
					[post_name] => zontiki
					[to_ping] => 
					[pinged] => 
					[post_modified] => 2019-02-19 17:33:48
					[post_modified_gmt] => 2019-02-19 14:33:48
					[post_content_filtered] => 
					[post_parent] => 0
					[guid] => http://wp-local.ru/?post_type=goods_post_type&p=158
					[menu_order] => 0
					[post_type] => goods_post_type
					[post_mime_type] => 
					[comment_count] => 0
					[filter] => raw
				)

		)

	[post_count] => 10
	[current_post] => -1
	[in_the_loop] => 
	[post] => WP_Post Object
		(
			[ID] => 167
			[post_author] => 1
			[post_date] => 2019-02-19 17:52:48
			[post_date_gmt] => 2019-02-19 14:52:48
			[post_content] => 
			[post_title] => Блины с картошкой
			[post_excerpt] => 
			[post_status] => publish
			[comment_status] => open
			[ping_status] => closed
			[post_password] => 
			[post_name] => bliny-s-kartoshkoj
			[to_ping] => 
			[pinged] => 
			[post_modified] => 2019-02-19 17:52:48
			[post_modified_gmt] => 2019-02-19 14:52:48
			[post_content_filtered] => 
			[post_parent] => 0
			[guid] => http://wp-local.ru/?post_type=goods_post_type&p=167
			[menu_order] => 0
			[post_type] => goods_post_type
			[post_mime_type] => 
			[comment_count] => 0
			[filter] => raw
		)

	[comment_count] => 0
	[current_comment] => -1
	[found_posts] => 12
	[max_num_pages] => 2
	[max_num_comment_pages] => 0
	[is_single] => 
	[is_preview] => 
	[is_page] => 
	[is_archive] => 
	[is_date] => 
	[is_year] => 
	[is_month] => 
	[is_day] => 
	[is_time] => 
	[is_author] => 
	[is_category] => 
	[is_tag] => 
	[is_tax] => 
	[is_search] => 
	[is_feed] => 
	[is_comment_feed] => 
	[is_trackback] => 
	[is_home] => 1
	[is_404] => 
	[is_embed] => 
	[is_paged] => 
	[is_admin] => 
	[is_attachment] => 
	[is_singular] => 
	[is_robots] => 
	[is_posts_page] => 
	[is_post_type_archive] => 
	[query_vars_hash:WP_Query:private] => e9b979dcd10228c0ab5e113c14b7ec54
	[query_vars_changed:WP_Query:private] => 
	[thumbnails_cached] => 
	[stopwords:WP_Query:private] => 
	[compat_fields:WP_Query:private] => Array
		(
			[0] => query_vars_hash
			[1] => query_vars_changed
		)

	[compat_methods:WP_Query:private] => Array
		(
			[0] => init_query_flags
			[1] => parse_tax_query
		)

)

**может категории как то в ядре WP не соединились с товарами.такое возможно ?
Помогите мне гуры WP :))

говорите что нужно отправить если не понятно.))**

0
Grayd2
5.1 год назад
На вопросы могут отвечать только зарегистрированные пользователи. Вход . Регистрация