我有一个自定义帖子类型crm,保存或更新每个crm后都需要发送一封邮件。我为某些自定义元(例如主题,用户等)使用cmb2,我知道在我使用两个参数(id和post)调用时,在save_post
保存后(根据WordPress Codex)钩子触发了,该帖子不包含更新值。这是我的代码:save_post
function send_mail_to_user($id, $post){
$crm = $post;
$user_email = array();
if($crm->vc_all_vc == 'on'){
$args = array('orderby' => 'display_name');
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
if (!empty($authors)) {
foreach ($authors as $author) {
array_push($user_email , $author->user_email );
}
}
}
else{
$to_users = $crm->vc_users;
$to_program = $crm->vc_program;
$to_group = $crm->vc_group;
$to_excode = $crm->vc_ex_code;
foreach ($to_users as $key => $value) {
$user_data = get_userdata($value);
array_push($user_email, $user_data->user_email);
}
foreach ($to_program as $key => $value) …
Run Code Online (Sandbox Code Playgroud) 我有 3 个级别的类别、类别、子类别和子子类别用于自定义帖子类型。我试图使用cmb2在下拉列表中显示这些类别,我的代码仅显示 2 个级别的类别,缺少第三个级别。
Category 1
-- child category 1
-- child category 2
-- addon category 1
-- addon category 2
-- child category 3
-- child category 4
-- addon category 1
-- addon category 2
Category 2
-- child category 1
-- child category 2
-- addon category 1
-- addon category 2
-- child category 3
-- child category 4
-- addon category 1
-- addon category 2
Run Code Online (Sandbox Code Playgroud)
我正在使用cmb2通过多选选项在 select2 中获取这些类别。 …
我正在尝试使用一组值运行 meta_query 并让它搜索是否所有都存在于存储在序列化数组中的元值中。这可能吗?
我的查询参数如下(注意这是嵌套在一个类中):
$args = array(
'post_type' => $this->posttype,
'posts_per_page' => '9',
'paged' => $paged,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_key' => 'lumens',
'meta_query' => array(
array(
'key' => 'mount',
'value' => array('pendant' , 'wall'),
'compare' => 'IN'
)
)
);
Run Code Online (Sandbox Code Playgroud)
存储的元数据的示例位于类似于以下的序列化数组中:
a:4:{i:0;s:7:"pendant";i:1;s:15:"surface-ceiling";i:2;s:4:"wall";i:3;s:14:"aircraft-cable";}
Run Code Online (Sandbox Code Playgroud)
无论我尝试什么,我的查询都不会返回适当的结果。我现在意识到我可能应该将每个值存储在不同的元键中,而不是存储在数组中,但是,现在已经有很多条目可以更改元数据。
更新:
这是我的解决方法,类似于@Leander 方法;由于数据库中已有的条目数量,我不想更改序列化输入,我忘记提及一件事,我正在使用CMB2 开发人员工具包,它将复选框字段存储为本地序列化数据。
// This is pulled from a user input
$meta_queries = array('pendent' , 'wall');
// Metaqueries are passed through loop to create single entries with the like comparison operator …
Run Code Online (Sandbox Code Playgroud)