如何按日期排序具有相同分类的多个自定义帖子类型

时间:2019-01-22 作者:Vedran Sadić

我使用这段代码按相同的分类法显示多个自定义帖子的列表,并按发布日期对其排序。但不知怎么的,它混淆了顺序。现场示例: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 ++;
                        ?> 

1 个回复
SO网友:Krzysiek Dróżdż

您使用\'orderby\' => \'publish_date\', 但是there is no such value for this parameter available.

它应该是:

\'orderby\' => \'date\',

相关推荐

如何在WooCommerce_Account_Orders函数中传递$CURRENT_PAGE?

woocommerce功能woocommerce_account_orders($current_page) 已调用1个参数$current_page. 该函数通过调用woocommerce_account_orders_endpoint 通过以下挂钩-add_action( \'woocommerce_account_orders_endpoint\', \'woocommerce_account_orders\' );然而,在上述挂钩中,$current_page 未在函数中作为参数传递。情况如何$c