从GET_CHILD数组中获取一个特定值

时间:2016-10-18 作者:Rafal

我有一个问题要解决。下面是Dokan插件创建的Woocommerce订单及其子订单的get\\u子订单数组,我正在尝试将其与另一个插件集成
我需要的是获取属于特定卖家(post\\u作者)的子订单(子post ID)。所以我得到的是:

父post ID-$预订->交易\\u ID-订单ID

  • post\\u作者-$卖家\\u ID-返回卖家ID

    $sub_orders = get_children( array(    
    \'post_parent\' => $reservation->transaction_id,    
    \'post_type\'   => \'shop_order\',    
    \'post_status\' => array( 
    \'wc-pending\', \'wc-completed\', \'wc-processing\', \'wc-on-hold\' 
    )
    ) );
    
    阵列返回:

    array ( 
    1810 => WP_Post::__set_state(array( 
    \'ID\' => 1810, 
    \'post_author\' =>\'post_author\' =>, 
    \'post_date\' => \'2016-10-16 22:13:35\', 
    \'post_date_gmt\' => \'2016-10-16 22:13:35\', 
    \'post_content\' => \'\', 
    \'post_title\' => \'Order – October 16, 2016 @ 10:13 PM\', 
    \'post_excerpt\' => \'\', 
    \'post_status\' => \'wc-processing\', 
    \'comment_status\' => \'open\', 
    \'ping_status\' => \'closed\', 
    \'post_password\' => \'order_5803fb8de7789\', 
    \'post_name\' => \'order-oct-16-2016-1013-pm-3\', 
    \'to_ping\' => \'\', 
    \'pinged\' => \'\', 
    \'post_modified\' => \'2016-10-16 22:13:35\', 
    \'post_modified_gmt\' => \'2016-10-16 22:13:35\', 
    \'post_content_filtered\' => \'\', 
    \'post_parent\' => 1808, 
    \'guid\' => \'https://example.com/?post_type=shop_order&p=1810\', 
    \'menu_order\' => 0, \'post_type\' => \'shop_order\', 
    \'post_mime_type\' => \'\', 
    \'comment_count\' => \'1\', 
    \'filter\' => \'raw\', )), 
    1809 => WP_Post::__set_state(array(
     \'ID\' => 1809, 
     \'post_author\' => \'2\', 
     \'post_date\' => \'2016-10-16 22:13:34\', 
     \'post_date_gmt\' => \'2016-10-16 22:13:34\', 
     \'post_content\' => \'\', 
     \'post_title\' => \'Order – October 16, 2016 @ 10:13 PM\', 
     \'post_excerpt\' => \'\', 
     \'post_status\' => \'wc-completed\', 
     \'comment_status\' => \'open\', 
     \'ping_status\' => \'closed\', 
     \'post_password\' => \'order_5803fb8dd09ed\', 
     \'post_name\' => \'order-oct-16-2016-1013-pm-2\', 
     \'to_ping\' => \'\', \'pinged\' => \'\', 
     \'post_modified\' => \'2016-10-16 23:48:58\', 
     \'post_modified_gmt\' => \'2016-10-16 23:48:58\', 
     \'post_content_filtered\' => \'\', 
     \'post_parent\' => 1808, 
     \'guid\' => \'https://example.com/?post_type=shop_order&p=1809\', 
     \'menu_order\' => 0, 
     \'post_type\' => \'shop_order\', 
     \'post_mime_type\' => \'\', 
     \'comment_count\' => \'2\', 
     \'filter\' => \'raw\', )), )
    

  • 1 个回复
    SO网友:birgire

    如果您想通过帖子作者进行查询,可以尝试author 输入参数:

    $sub_orders = get_children( 
        array(    
            \'author\'      => $seller_id,
            \'post_parent\' => $reservation->transaction_id,    
            \'post_type\'   => \'shop_order\',    
            \'post_status\' => array( 
                \'wc-pending\', 
                \'wc-completed\', 
                \'wc-processing\', 
                \'wc-on-hold\' 
            )
        ) 
    );
    
    请注意get_children() 呼叫get_posts(), 这又是一个包装WP_Query, 所以您可以使用author_name, author__inauthor__not_in 输入参数。

    相关推荐