开发者

save the data of custom metabox to database

开发者 https://www.devze.com 2023-04-07 10:39 出处:网络
I want to save the data of my custommeta box to the corresponding table in a field. my custom metabox..

I want to save the data of my custom meta box to the corresponding table in a field. my custom metabox..

add_action( 'admin_init', 'blc_add_custom_link_box', 1 );
add_action( 'save_post', 'blc_save_linkdata' );
function blc_add_custom_link_box() {
    add_meta_box( 
        'backlinkdiv',
        'Backlink URL',
        'blc_backlink_url_input',
        'link',
        'normal',
        'high'
    );
}
function blc_backlink_url_input( $post ) {

  // Use nonce for verification
  wp_nonce_field( plugin_basename( __FILE__ ), 'blc_noncename' );

  // The actual fields for data entry
  echo '<input type="text" id="backlink-url" name="backlink_url" value="put your backlink here" size="60" />';
function blc_save_linkdata( $link_id ) {
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
      return;
  if ( !wp_verify_nonce( $_POST['blc_noncename'], plugin_basename( __FILE__ ) ) )
      return;
  if ( 'link' == $_POST['link_type'] ) 
  {
    if ( ! current_user_can( 'edit_page', $link_id ) )
        return;
  }
  else
  {
    if ( !current_user_can( 'edit_post', $link_id ) )
        return;
  }
  $blc_linkdata = $_POST['blc_link'];
?>

now i want to store the data in to the database table WP_link in a custom field. i got meta box in the link edi开发者_高级运维t admin page . but it cant save the data in database. how it can be save in database table wp_link. I want know how to save the $blc_linkdata from custom metafield from the link edit page. Plz help..


You should find this page on the Wordpress Codex useful: http://codex.wordpress.org/Function_Reference/add_post_meta


I would simply use the Meta Box Script from DeluxeBlogTips.

I'm also working on a (huge) site that requires (many) metabox/custom field integrations. Trust me, this will save you lots of time and is well written and thoroughly tested ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消