Ecommerce Shopify WordPress Discussion

Saving metadata in WordPress elements

I have a problem with meta of post in Wordpress. The problem is that under seemingly identical conditions, element e1 writes metadata, but element e2 does not. Any ideas on how to cure this? My functions are: function r_func( $post ) { wp_nonce_field (basename( __FILE__ ), 'e1' ); wp_nonce_field (basename( __FILE__ ), 'e2' ); $custom1 = get_post_meta( $post->ID, 'e1', true ); $custom2 = get_post_meta( $post->ID, 'e2', true );?> <label for="e1">CCC</label> <input name="e1" type="date" id="e1" value="<?php echo esc_attr($custom1); ?>"> <p><label for="e2">LLL</label><br/> <input type="text" name="e2" id="e2" value="<?php echo esc_attr($custom2); ?>"/></p> <?php } function ev( $post_id, $post ) { if ( !isset( $_POST['e1'] ) || !wp_verify_nonce( $_POST['e1'], basename( __FILE__ ) ) ) return $post_id; if ( !isset( $_POST['e2'] ) || !wp_verify_nonce( $_POST['e2'], basename( __FILE__ ) ) ) return $post_id; update_post_meta($post_id, 'e2', $_POST['e2']); update_post_meta($post_id, 'e1', $_POST['e1']); } Function ev() is attached to a hook: add_action( 'save_post', 'ev', 10, 2 ); Same for r_func: function add_mb( $post_type, $post ) { add_meta_box('meta1', 'My_meta', 'r_func', 'post', 'side', 'high'); } add_action( 'add_meta_boxes', 'add_mb', 10, 2 );
wp_nonce_field (basename( __FILE__ ), 'e1' ); ... <input name="e1" type="date" id="e1" value="<?php echo esc_attr($custom1); ?>"> ... Your text input fields have the same names as those nonce fields, e1 and e2 - so the resulting parameters will overwrite each other, when the form gets submitted. You need to name your nonce fields something else. And nonces are not "field-based" - you should not be adding a nonce for each form field here, but only one nonce for the entire form.

February 17, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.