I have created custom meta box field product_statuss
to my CPT product. I want to predefine four possible statuses and display them as dropdown list but have spent 4+ hour running the same error.
Here is the code that works fine:
add_action( 'add_meta_boxes', 'product_statuss_box' );
function product_statuss_box() {
add_meta_box(
'product_statuss_box',
__( 'Product Statuss', 'myplugin_textdomain' ),
'product_meta_callback',
'product',
'side',
'high'
);
}
function product_meta_callback( $post ) {
wp_nonce_field( plugin_basename( __FILE__ ), 'product_meta_callback_nonce' );
$product_stored_meta = get_post_meta( $post->ID );
echo '<label for="product_statuss" class="product-row-title"></label>';
echo '<input type="text" id="product_statuss" name="product_statuss" placeholder="enter a statuss" />';
}
At this site I found this code:
<p>
<label for="product_statuss" class="product-row-title"><?php _e( 'Example Select Input', 'product-textdomain' )?></label>
<select name="product_statuss" id="product_statuss">
<option value="select-one" <?php if ( isset ( $product_stored_meta['product_statuss'] ) ) selected( $product_stored_meta['product_statuss'][0], 'select-one' ); ?>><?php _e( 'One', 'product-textdomain' )?></option>';
<option value="select-two" <?php if ( isset ( $product_stored_meta['product_statuss'] ) ) selected( $product_stored_meta['product_statuss'][0], 'select-two' ); ?>><?php _e( 'Two', 'product-textdomain' )?></option>';
</select>
</p>
but whenever I run it the browser show "page isn’t working". I tracked down to
tag usage. Page crushed even when I changed the code in product_meta_callback
to this:
<p>
<label for="product_price" class="product-row-title"></label>
<input type="text" id="product_price" name="product_price" placeholder="enter a price" />
</p>
Can someone please help me understand what am I doing wrong?