0
我想增加通过Wordpress的批量发布编辑菜单更新元值的能力。我有一个单一的职位工作,但我不明白为什么它不适用于散装。WordPress的批量发布元更新
// Add our text to the quick & bulk edit box
add_action('quick_edit_custom_box', 'on_quick_edit_custom_box', 10, 2);
add_action('bulk_edit_custom_box', 'on_quick_edit_custom_box', 10, 2);
function on_quick_edit_custom_box($column_name, $post_type) {
global $post;
$postMeta = get_post_meta($post->ID, 'wpsl_locatorID', true);
if ('wpsl_locatorID' == $column_name && get_post_type() == 'location') {
echo "<fieldset class=\"inline-edit-col-right\" style=\"margin-top: 0;\">";
echo "<div class=\"inline-edit-col\">";
echo "<div class=\"inline-edit-group\">";
echo "<label class=\"alignleft\">";
echo "<span class=\"title\" for=\"wpsl_locatorID\">Movie ID</span>";
echo "<input type=\"text\" name=\"wpsl_locatorID\" id=\"wpsl_locatorID\" value=\"{$postMeta}\" />";
echo "</label>";
echo "</div>";
echo "</fieldset>";
};
}
// Update the post meta
add_action('save_post', 'locationMetaUpdate', 10, 2);
function locationMetaUpdate($post_id) {
// Bail if we're doing an auto save
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
// if our nonce isn't there, or we can't verify it, bail
// if un-commented than the value won't update at all. I'm guessing b/c of WP's ajax function vs. reloading the page.
//if(!isset($_POST['meta_box_nonce']) || !wp_verify_nonce($_POST['meta_box_nonce'], 'my_meta_box_nonce')) return;
// if our current user can't edit this post, bail
if (! current_user_can('edit_posts')) return;
// Make sure that it is set.
if (! isset($_POST['wpsl_locatorID'])) {
return;
}
// Sanitize user input.
$my_data = sanitize_text_field($_POST['wpsl_locatorID']);
// Update the meta field in the database.
update_post_meta($post_id, 'wpsl_locatorID', $my_data);
};
就像我上面说过的,这适用于单个快速编辑,但不适用于批量编辑。我试图找到一个解决方案,但我相信这是我错过的简单东西。