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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog