当发布自定义类型(“my-solutions”)时,我试图用自定义值填充Posteta表。我读了一些线索,抄本和Pippin\'s blog 在这件事上,他尝试了很多变化,但都没能成功。如果有人可以添加或更正任何内容,那将是非常棒的。
function run_when_my_solution_published( $post ){
global $wpdb;
$id = $post->ID;
if($post->post_type == \'my-solutions\'){
$wpdb->insert(\'wp_postmeta\', array( \'meta_id\' => NULL ,
\'post_id\' => $id ,
\'meta_key\' => \'my_json\' ,
\'meta_value\' => \'json\' ),
array( \'%d\' , \'%d\' , \'%s\' , \'%s\' )
);
}
}
add_action(\'new_to_publish\', \'run_when_my_solution_published\');