E
E
Evgenij Popov2021-07-13 08:55:46
WordPress
Evgenij Popov, 2021-07-13 08:55:46

There is no way to select a category when creating a page - how to arrange it?

Hello everyone
When creating a new entry, there is a category selection. In addition, the content of one section on the site is not displayed yet. https://elektro-spb.ru/category/obrazcy-proektov/
It is full of pages. The content of the other category is displayed. https://elektro-spb.ru/category/rubrika-statej/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2021-07-13
@evgenijpopov

Code to add categories and tags to pages

function add_taxonomies_to_pages() {
 register_taxonomy_for_object_type( 'post_tag', 'page' );
 register_taxonomy_for_object_type( 'category', 'page' );
 }
add_action( 'init', 'add_taxonomies_to_pages' );
 if ( ! is_admin() ) {
 add_action( 'pre_get_posts', 'category_and_tag_archives' );
 
 }
function category_and_tag_archives( $wp_query ) {
$my_post_array = array('post','page');
 
 if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) )
 $wp_query->set( 'post_type', $my_post_array );
 
 if ( $wp_query->get( 'tag' ) )
 $wp_query->set( 'post_type', $my_post_array );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question