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() {
        __( 'Product Statuss', 'myplugin_textdomain' ),
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:

    <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>';

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:

<label for="product_price" class="product-row-title"></label>
<input type="text" id="product_price" name="product_price" placeholder="enter a price" />

Can someone please help me understand what am I doing wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.