It is necessary to obtain a list of all categories from a custom type of records, each of which will contain a list of records belonging to it. Like this:
ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ Π ΠΠ°ΠΏΠΈΡΡ ΠΊΠ°Ρ Π 1 ΠΠ°ΠΏΠΈΡΡ ΠΊΠ°Ρ Π 2 ΠΠ°ΠΏΠΈΡΡ ΠΊΠ°Ρ Π N ... ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ B ...
and so on.
In the template I try to combine the functions get_categories()
and get_posts()
:
$args = array( 'type' => 'glossary', 'child_of' => 0, 'parent' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'number' => 0, 'taxonomy' => 'gl_section', 'pad_counts' => false ); $categories = get_categories( $args ); if( $categories ){ foreach( $categories as $cat ){ // ΠΠ°Π½Π½ΡΠ΅ Π² ΠΎΠ±ΡΠ΅ΠΊΡΠ΅ $cat $id = $cat->term_id; $title = $cat->name; echo $id; echo $title; $args = array('category' => $id, 'post_type' => 'glossary' , 'category_name' => $title); print_r( get_posts($args) ); } }
Result:
70 D Array ( ) 69 F Array ( ) 71 G Array ( )
That is, the category ID and title are displayed, but no posts. I tried to look for a function that displays everything at once - I did not find it. What other ways can there be? Or in WP, in principle, it is impossible to combine records and taxonomy?
Another problem has also come to light: even if I assign a 'category' => ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½ΠΎΠ΅ ΡΠΈΡΠ»ΠΎΠ²ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅
parameter in the $args
array, the effect is the same, an empty array is output.