2017-09-18 61 views
1

我正在嘗試調用過濾器中的操作。我想要從動作方法的值,並用它來過濾功能從wordpress中的add_action中檢索值

add_filter('wc_product_table_query_args', 'wcpt_custom_query_args', 10, 3); 

function wcpt_custom_query_args($args, $product_table) { 
add_action('dokan_store_profile_frame_after', 'add_store_id', 13, 2); 
     ; 

    // do something with $args 
$args += array('author' => $store_id); 

    return $args; 
} 

function add_store_id($store_user, $store_info){ 
    $store_id = $store_user->ID;  
    return $store_id; 

} 

我怎樣才能檢索功能wcpt_custom_query_args裏面的$ STORE_ID?

回答

1
add_action('dokan_store_profile_frame_after', 'add_store_id', 13, 2); 

function add_store_id($store_user, $store_info){ 
    global $store_id; 
    $store_id = $store_user->ID;  
    add_filter('wc_product_table_query_args', 'wcpt_custom_query_args', 10, 2); 
} 

function wcpt_custom_query_args($args, $product_table) { 
global $store_id; 
    // do something with $args 
$args += array('author' => $store_id); 

    return $args; 
} 
+0

全局不工作...我已經嘗試過:( – Himani

+1

請先加載add_store_id之後比wcpt_custom_query_args funciton –

+0

非常感謝...通過加載add_store_id函數它工作:) :) :) – Himani

0

您應該在您的源代碼中找到apply_filter('wc_product_table_query_args'行以查找允許的參數。如果第三參數是$ store_id,那麼你可以使用它。你應該記住,行動掛鉤

一兩件事,沒有什麼應退還(只返回篩選器掛鉤)

+0

apply_filter(「wc_product_table_query_args」由只有兩個參數,其中沒有一個是$ STORE_ID – Himani

+0

你能嘗試var_dump $ args,$ product_table來查看任何參數可用於獲取$ store_user和$ store_id? –

+0

不能從這些參數猜測 – Himani