WordPress.org

Ready to get started?Download WordPress

Forums

error on update_metadata (2 posts)

  1. Angela
    Member
    Posted 1 year ago #

    I have a custom metadata table for taxonomy.

    CREATE TABLE IF NOT EXISTS taxonomymeta (
    meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    taxonomy_id bigint(20) unsigned NOT NULL DEFAULT '0',
    meta_key varchar(255) DEFAULT NULL,
    meta_value longtext,
    PRIMARY KEY (meta_id),
    KEY taxonomy_id (taxonomy_id),
    KEY meta_key (meta_key)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

    My PHP code is as follows. But the data doesn't get inserted into the table. Why?

    <?php
    add_action('category_add_form_fields', 'category_metabox_add', 10, 1);
    add_action('category_edit_form_fields', 'category_metabox_edit', 10, 1);
    add_action('created_category', 'update_category_metadata', 10, 1);
    add_action('edited_category', 'update_category_metadata', 10, 1);
    
    function category_metabox_add($tag) {
    	$output = '
    	<div class="form-field">
    		<label for="price">价格</label>
    		<input name="price" type="number">
    	</div>
    	';
    	echo $output;
    }
    
    function category_metabox_edit($tag) {
    	$output = '
    	<tr class="form-field">
    		<th scope="row" valign="top">
    			<label for="price">Pricing</label>
    		</th>
    		<td>
    			<input name="price" type="number" value="' . get_metadata("taxonomy", $tag->term_id, "price", true) . '">
    		</td>
    	</tr>
    	';
    	echo $output;
    }
    
    function update_category_metadata($term_id) {
    	update_metadata("taxonomy", $term_id, "pricing", $_POST['pricing']);
    }
    ?>
  2. ryscript
    Member
    Posted 1 year ago #

    Same here it didn't save even I applied filter and action after add function, would be great is WP provide more sample and documentation, don't have time to try and dig in myself :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.