A
A
Alexander Tokmakov2016-03-30 14:59:00
PHP
Alexander Tokmakov, 2016-03-30 14:59:00

How to display wordpress posts like this?

Hello.
I have a custom post type "Products".
there are many categories (vegetables, fruits, etc.)
I want to display in this way on the page:
category vegetables
- entry cucumber
- entry potato
category fruit
- entry apple
- entry pear
alcohol category
- entry beer
- entry wine
I managed to make a list of categories and a list of articles, but not together.
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Tokmakov, 2016-03-31
@calliko

I asked myself, I answered

<?php
            $arguments = array(
                'orderby'      => 'name',
                'order'        => 'ASC',
                'number'       => 0,
                'taxonomy'     => 'calc_cat',
                'field'    => 'slug',
                       );
            $cats = get_categories($arguments);
            foreach ($cats as $cat) {
                echo $cat->cat_name;  // Получаем название одной категории


                $psts = query_posts( array(
                    'posts_per_page' => -1,
                    'post_type' => 'calc',
                    'order'     => 'ASC',
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'calc_cat',
                            'field'    => 'slug',
                            'terms'    => $cat->cat_name
                        ))
                ) );

                foreach( $psts as $pst ){
                    echo   $pst->post_title;//вывод продукта
                                   }

            } wp_reset_query();
            ?>

L
Laid, 2016-03-30
@stoik_kpd

Write the word "vegetables"
and then the cycle of displaying records, indicating the id or slugs or category names from which you want to display records
wp-kama.ru/function/wp_query
Close the cycle.
And the same

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question