Нужна небольшая помощь с этим кодом. Я сталкиваюсь с этой проблемой около 2 дней, но не могу понять.
Я хочу получить имя своего пользовательского типа сообщений, которое я зарегистрировал.
$type = get_post_type();
echo "Post type is $type";
if(get_query_var( 'post_type' ) !== 'jobs'){
return $original_template;
}
Как я зарегистрировал свой собственный тип сообщения, описано ниже:
function dwwp_register_post_type() {
$singular = __( 'Job' );
$plural = __( 'Jobs' );
//Used for the rewrite slug below.
$plural_slug = str_replace( ' ', '_', $plural );
//Setup all the labels to accurately reflect this post type.
$labels = array(
'name' => $plural,
'singular_name' => $singular,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $singular,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular,
'new_item' => 'New ' . $singular,
'view' => 'View ' . $singular,
'view_item' => 'View ' . $singular,
'search_term' => 'Search ' . $plural,
'parent' => 'Parent ' . $singular,
'not_found' => 'No ' . $plural .' found',
'not_found_in_trash' => 'No ' . $plural .' in Trash'
);
//Define all the arguments for this post type.
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-admin-site',
'can_export' => true,
'delete_with_user' => false,
'hierarchical' => true,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
// 'capabilities' => array(),
'rewrite' => array(
'slug' => 'jobs',
'with_front' => false,
),
'supports' => array(
'title'
)
);
//Create the post type using the above two varaiables.
register_post_type( 'jobs', $args);
}
Подробнее здесь: https://stackoverflow.com/questions/421 ... -post-type
Почему я не получаю имя своего пользовательского типа сообщения с помощью get_post_type() ⇐ Php
Кемеровские программисты php общаются здесь
1728525438
Anonymous
Нужна небольшая помощь с этим кодом. Я сталкиваюсь с этой проблемой около 2 дней, но не могу понять.
Я хочу получить имя своего пользовательского типа сообщений, которое я зарегистрировал.
$type = get_post_type();
echo "Post type is $type";
if(get_query_var( 'post_type' ) !== 'jobs'){
return $original_template;
}
Как я зарегистрировал свой собственный тип сообщения, описано ниже:
function dwwp_register_post_type() {
$singular = __( 'Job' );
$plural = __( 'Jobs' );
//Used for the rewrite slug below.
$plural_slug = str_replace( ' ', '_', $plural );
//Setup all the labels to accurately reflect this post type.
$labels = array(
'name' => $plural,
'singular_name' => $singular,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $singular,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular,
'new_item' => 'New ' . $singular,
'view' => 'View ' . $singular,
'view_item' => 'View ' . $singular,
'search_term' => 'Search ' . $plural,
'parent' => 'Parent ' . $singular,
'not_found' => 'No ' . $plural .' found',
'not_found_in_trash' => 'No ' . $plural .' in Trash'
);
//Define all the arguments for this post type.
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-admin-site',
'can_export' => true,
'delete_with_user' => false,
'hierarchical' => true,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
// 'capabilities' => array(),
'rewrite' => array(
'slug' => 'jobs',
'with_front' => false,
),
'supports' => array(
'title'
)
);
//Create the post type using the above two varaiables.
register_post_type( 'jobs', $args);
}
Подробнее здесь: [url]https://stackoverflow.com/questions/42198188/why-im-not-getting-my-custom-post-type-name-with-get-post-type[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия