I have defined a custom post type for creating galleries using WP built in gallery functionality.
register_post_type( 'my_gallery',
array(
'labels' => array(
'name' => __( 'Gallery', 'my-child-theme' ),
'singular_name' => __( 'Gallery', 'my-child-theme' )
),
'public' => true,
'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' )
)
);
Also created custom taxonomy for this specific CPT, with a main category 'Galleries', and a subcategory 'History':
-Galleries
-History
I also have a template in child theme called taxonomy-galleries.php which works as it should, it displays all the posts in galleries, and in history too.
Now what I want is this: Display all the posts in main category, and display the subcategory history, paged with max 12 elements.
How would I do that?
Edit based on @mmm -s answer how to get all the elements in one array:
$all_the_items = array();
while ( have_posts() ) : the_post();
$t = get_the_terms( $post->ID , 'my-taxonomy' );
if ($t[0]->parent == 0){
$properties = array(
'title' => get_the_title(),
'link' => get_the_permalink() );
$all_the_items[] = $properties;
}
endwhile; wp_reset_query();
$o = get_queried_object();
$children = get_term_children($o->term_id, $o->taxonomy);
foreach ($children as $child) {
$this_term = get_term($child);
$properties = array(
'title' => $this_term->name,
'link' => site_url('/' . $this_term->taxonomy . '/' . $this_term->slug . '/')
);
}