Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress-在搜索查询中包含来自新列的数据_Wordpress_Woocommerce - Fatal编程技术网

Wordpress-在搜索查询中包含来自新列的数据

Wordpress-在搜索查询中包含来自新列的数据,wordpress,woocommerce,Wordpress,Woocommerce,我在Woocommerce orders的屏幕上添加了一个新列,指出谁是订单的创建者(在该网站上,服务代表可以在后端为客户创建订单)。问题是,当我在orders屏幕中搜索该数据时,我找不到任何数据。 订单的创建者被设置为带有dd\u post\u meta() 所以我试过这样的方法: function include_search( $query ) { if ( is_admin() && $query->is_search() && $query

我在Woocommerce orders的屏幕上添加了一个新列,指出谁是订单的创建者(在该网站上,服务代表可以在后端为客户创建订单)。问题是,当我在orders屏幕中搜索该数据时,我找不到任何数据。 订单的创建者被设置为带有
dd\u post\u meta()
所以我试过这样的方法:

function include_search( $query ) {
    if ( is_admin() && $query->is_search() && $query->query['post_type'] == 'shop_order' ) {
        $query->set( 'meta_query', array('key' => 'representative', 'value' => $query->query['s'], 'compare' => '=') );
    }
}
add_action( 'pre_get_posts', 'include_search' );
但它不起作用

例如,如果订单是由“Ben X”创建的,那么我可以在订单屏幕的右栏中看到他的名字,但是如果我在搜索框中搜索“Ben X”,我就找不到该订单

有什么帮助吗


谢谢

如果有人需要帮助,我找到了答案:

function filter_woocommerce_shop_order_search_fields( $array ) {
    $array[] = 'representative'; //The order meta key that needs to be include in the search
    return $array;
};
add_filter( 'woocommerce_shop_order_search_fields', 'filter_woocommerce_shop_order_search_fields', 10, 1 );