$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to order multiple custom post types with same taxonomy by date|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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',
Post a comment

comment list (0)

  1. No comments so far