0

I am trying to show in a single post child category from a selected category. For some single post, I have a category that is corresponding to an area. I want to show that category in a special area of my single post template.

I tried several ways but I can't do it. So far here I am back at the start calling the post categories :

$regions = get_the_category( array(
        'parent' => '62',
    ));

Anyone can help me? Thank you

0

Well in the end I used custom taxonomy, and it's also more simple to manage. I post as I did :

//hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires
 
add_action( 'init', 'create_regions_nonhierarchical_taxonomy', 0 );
 
function create_regions_nonhierarchical_taxonomy() {
 
// Labels part for the GUI
 
  $labels = array(
    'name' => _x( 'Regions', 'Where are located activities or place of interests' ),
    'singular_name' => _x( 'Region', 'Regions singular name' ),
    'search_items' =>  __( 'Search Regions' ),
    'popular_items' => __( 'Popular Regions' ),
    'all_items' => __( 'All Regions' ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit Region' ), 
    'update_item' => __( 'Update Region' ),
    'add_new_item' => __( 'Add New Region' ),
    'new_item_name' => __( 'New Region Name' ),
    'separate_items_with_commas' => __( 'Separate regions with commas' ),
    'add_or_remove_items' => __( 'Add or remove regions' ),
    'choose_from_most_used' => __( 'Choose from the most used regions' ),
    'menu_name' => __( 'Regions' ),
  ); 
 
// Now register the non-hierarchical taxonomy like tag
 
  register_taxonomy('regions','post',array(
    'hierarchical' => false,
    'labels' => $labels,
    'show_ui' => true,
    'show_in_rest' => true,
    'show_admin_column' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => 'region', 'with_front' => false),
  ));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.