dplece1882 2017-02-14 10:13
浏览 40
已采纳

Wordpress AJAX通过Meta_VALUE_NUM加载更多订单

Helo, I have multiple meta_key value pairs inside my custom posts. So to work around this what I did is that I ran a WP_QUERY initially which creates an array of posts ID which I then pass to load more to load those.

The array that I build using WP_Query is in the correct order. However when I use the IDs in post_in parameter it is not displaying them in the given order. I have also tried to give orderby="meta_value_num" parameter but it doesnt work either.

Here is WP_QUERY which is working perfectly

$loop = new WP_Query( 
                                array( 
                                      'post_type' => 'properties', 
                                      'posts_per_page' => -1,
                                        'meta_query' => array(
                                                array(
                                                    'key' => 'listing_type',
                                                    'value'   => array(3,2),
                                                    'type'   => 'NUMERIC',
                                                ),
                                                array(
                                                    'key'     => 'payment_status',
                                                    'value'   => 'yes',

                                                        ),                                              
                                                array(
                                                    'key'     => 'expired',
                                                    'value'   => 'no',



 - ),

                        ),
                                        'orderby' => 'meta_value_num',
                                        'meta_key' => 'listing_type',
                                        'order' => 'DESC' 
                                      )); 

Here is the shortcode:

[ajax_load_more post_type="properties" post__in="'.implode(',',$featured).'" posts_per_page="10" scroll="false" transition="fade" button_label="'.$l_more.'" button_loading_label="'.$l_more_2.'" container_type="ul" css_classes="items",orderby="meta_value_num" meta_key="listing_type"]

However it doesnt order posts as it should because $featured array has it in required order. Even if I remove order by and meta_key parameter it doesnt work.

Please Help Ahmar

  • 写回答

1条回答 默认 最新

  • duanhui1869 2017-02-14 19:23
    关注

    First, you have an error in your shortcode.

    [ajax_load_more post_type="properties" post__in="'.implode(',',$featured).'" posts_per_page="10" scroll="false" transition="fade" button_label="'.$l_more.'" button_loading_label="'.$l_more_2.'" container_type="ul" css_classes="items" orderby="meta_value_num" meta_key="listing_type"]
    

    Second, you should orderby="post__in" to preserve the post__in ordering. https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计