how to code show categories and single post by category



echo get_queried_object () -> term_id;

// set up taxonomies

$ tax_one = ‘products’;

$ post_type = ‘menubumi’;


$ categories = get_categories (array (

‘Type’ => $ post_type,

‘Orderby’ => ‘name’,

‘Order’ => ‘ASC’,

‘Hide_empty’ => 0,

‘Hierarchical’ => 1,

‘Taxonomy’ => $ tax_one));


foreach ($ categories as $ category): // list all categories








echo ‘’;


endforeach;

$ myquery = (

‘Post_type’ => ‘menubumi’,



);


$ args = array (

‘Post_type’ => ‘menubumi’,


‘Tax_query’ => array (

array (

‘Taxonomy’ => ‘products’, // taxonomy name

‘Field’ => ‘term_id ', // term_id, slug or name

‘Terms’ => get_queried_object () -> term_id, // term id, term slug or term name

‘Posts_per_page’ => -1,

)

)

);

$ query = new WP_Query ($ args);

if ($ query-> have_posts ()) {

while ($ query-> have_posts ()) {

$ query-> the_post ();

the_title ();

} // end while

} // end if

wp_reset_query ();



?>


The post how to code show category and single post by category appeared first on Blog community.

About My name is Nguyen Manh Cuong. I was born in a poor village in Ba Vi district, HA NOI province - windy and sunny land. Currently. https://www.nguyendiep.com/. Mr Cuong.
Newer Posts Newer Posts Older Posts Older Posts

Comments

Post a Comment