How to order multiple custom post types with same taxonomy by date

admin2025-06-04  0

I am using this code to display list of multiple custom posts by same taxonomy and order them by date publishing. But somehow it mixed the order. The live example: /

<?php 
        $queryTmp = new WP_Query(
                                array(
                                    'posts_per_page' => 30, //return 30 posts
                                    'post_status' => 'publish', //only published posts
                                    'post_type' => array(
                                        'pr_baterijska_napaja',
                                        'pr_cd_sacd_playeri',
                                        'pr_dac_digitalni_kon',
                                        'pr_gramofoni',
                                        'pr_gramofonske_rucke',
                                        'pr_gramofonske_zvucn',
                                        'pr_dac_digitalni_kon',
                                        'pr_hifi_police_namje',
                                        'pr_kabeli_inte',
                                        'pr_kabeli_stru',
                                        'pr_muzicki_serv-dac',
                                        'pr_muzicki_serveri',
                                        'pr_phono-predpojacal',
                                        'pr_pojacala_integrir',
                                        'pr_pojacala_izlazna',
                                        'pr_predpojacala',
                                        'pr_strujne_letve',
                                        'pr_strujni_filteri',
                                        'pr_tuneri',
                                        'pr_usb_converteri',
                                        'pr_zvucnicke_kutije',
                                        'pr_zvucnicki_kablovi',
                                        'pr_pribor',
                                        ),

                                    'order'   => 'DESC',
                                    'orderby' => 'publish_date',
                                    'tax_query' => array(
                                        array(
                                            'taxonomy' => 'atribut-proizvoda',
                                            'field' => 'slug',
                                            'terms' => 'dostupno'
                                        ),
                                    ),
                                )
                            );

                            $i= 0;
                            if ($queryTmp->have_posts()) : 
                            $iii ++;
                        ?> 

I am using this code to display list of multiple custom posts by same taxonomy and order them by date publishing. But somehow it mixed the order. The live example: https://planetaudio.hr/novo-u-planetu/

<?php 
        $queryTmp = new WP_Query(
                                array(
                                    'posts_per_page' => 30, //return 30 posts
                                    'post_status' => 'publish', //only published posts
                                    'post_type' => array(
                                        'pr_baterijska_napaja',
                                        'pr_cd_sacd_playeri',
                                        'pr_dac_digitalni_kon',
                                        'pr_gramofoni',
                                        'pr_gramofonske_rucke',
                                        'pr_gramofonske_zvucn',
                                        'pr_dac_digitalni_kon',
                                        'pr_hifi_police_namje',
                                        'pr_kabeli_inte',
                                        'pr_kabeli_stru',
                                        'pr_muzicki_serv-dac',
                                        'pr_muzicki_serveri',
                                        'pr_phono-predpojacal',
                                        'pr_pojacala_integrir',
                                        'pr_pojacala_izlazna',
                                        'pr_predpojacala',
                                        'pr_strujne_letve',
                                        'pr_strujni_filteri',
                                        'pr_tuneri',
                                        'pr_usb_converteri',
                                        'pr_zvucnicke_kutije',
                                        'pr_zvucnicki_kablovi',
                                        'pr_pribor',
                                        ),

                                    'order'   => 'DESC',
                                    'orderby' => 'publish_date',
                                    'tax_query' => array(
                                        array(
                                            'taxonomy' => 'atribut-proizvoda',
                                            'field' => 'slug',
                                            'terms' => 'dostupno'
                                        ),
                                    ),
                                )
                            );

                            $i= 0;
                            if ($queryTmp->have_posts()) : 
                            $iii ++;
                        ?> 
Share Improve this question edited Jan 22, 2019 at 10:36 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jan 22, 2019 at 10:17 Vedran SadićVedran Sadić 311 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

You use 'orderby' => 'publish_date', but there is no such value for this parameter available.

It should be:

'orderby' => 'date',
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748987534a315410.html

最新回复(0)