我想在Wordpress中添加一個action,這樣當保存類型'fep_message'的帖子時,我檢查與post_parent ID關聯的任何'_fep_delete_by_'鍵以及然後我從wp_post_meta表中刪除它們。這是我建立的代碼,但它不工作:在保存後類型時運行在wordpress中運行一個函數
add_action('publish_post', 'undelete_thread');
function undelete_thread($post_id, $post) {
global $wpdb;
if ($post->post_type = 'fep_message'){
$participants = fep_get_participants($post->post_parent);
foreach($participants as $participant)
{
$query ="SELECT meta_id FROM wp_postmeta WHERE post_id = %s and `meta_key` = '_fep_delete_by_%s'";
$queryp = $wpdb->prepare($query, array($post->post_parent, $participant));
if (!empty($queryp)) {
delete_post_meta($queryp,'_fep_delete_by_' . $participant);
}
}
}
}
什麼是正確的掛鉤,以完成這項工作?