Skip to content

Instantly share code, notes, and snippets.

@Dziuperman
Created July 19, 2019 09:57
Show Gist options
  • Save Dziuperman/d2417885cc014c370eba04e47e1c718d to your computer and use it in GitHub Desktop.
Save Dziuperman/d2417885cc014c370eba04e47e1c718d to your computer and use it in GitHub Desktop.
// Добавление рубрик и меток страницам
function true_apply_categories_for_pages(){
add_meta_box( 'categorydiv', 'Категории', 'post_categories_meta_box', 'page', 'side', 'normal'); // добавляем метабокс категорий для страниц
register_taxonomy_for_object_type('category', 'page'); // регистрируем рубрики для страниц
}
// обязательно вешаем на admin_init
add_action('admin_init','true_apply_categories_for_pages');
function true_expanded_request_category($q) {
if (isset($q['category_name'])) // если в запросе присутствует параметр рубрики
$q['post_type'] = array('post', 'page'); // то, помимо записей, выводим также и страницы
return $q;
}
add_filter('request', 'true_expanded_request_category');
if(!function_exists('delfiGetTermsRecursive')) {
function delfiGetTermsRecursive($id, &$terms) {
if($id > 0) {
$term = get_term((int) $id, 'category');
$terms[] = $term;
if($term->parent > 0) {
delfiGetTermsRecursive($term->parent, $terms);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment