我想知道只有在更新或添加新帖子时,如何才能插入DB行(与WordPress表无关)。现在我有这个。。。
add_action( \'save_post\', \'insertIntoDBatPost\');
function insertIntoDBatPost()
{
global $wpdb;
global $post;
$wpdb->show_errors();
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if ( defined( \'DOING_AJAX\' ) && DOING_AJAX )
return;
$ios_version_changelog = isset($_POST[\'ios_version_changelog\']) ? $_POST[\'ios_version_changelog\'] : \'\';
$ios_version_release_date = isset($_POST[\'ios_version_release_date\']) ? $_POST[\'ios_version_release_date\'] : \'\';
$ios_version_download_link = isset($_POST[\'ios_version_download_link\']) ? $_POST[\'ios_version_download_link\'] : \'\';
$ios_version_log = isset($_POST[\'ios_version_log\']) ? $_POST[\'ios_version_log\'] : \'\';
if($ios_version_log != \'\')
{
$wpdb->insert(
\'posts_details\',
array(
\'post_id\' => $post->ID,
\'post_changelog\' => $ios_version_changelog,
\'post_release_date\' => $ios_version_release_date,
\'post_download_link\' => $ios_version_download_link,
\'post_ios_version\' => $ios_version_log
)
);
}
}
WordPress会不时自动保存,这会在我的数据库中插入很多行。
有什么想法吗?