Add/edit custom fields in wordpress












0















I have added a custom wordpress field via the following code, but I cannot save the new value for it when I click on edit. When I edit, the value always shows as empty. What am I doing wrong?



<?php
update_option( 'siteurl', 'http://2018.hellotreelb.com/luxin' );
update_option( 'home', 'http://2018.hellotreelb.com/luxin' );
/**
*
* @link https://codex.wordpress.org/Theme_Development
* @link https://codex.wordpress.org/Child_Themes
*
* Functions that are not pluggable (not wrapped in function_exists()) are
* instead attached to a filter or action hook.
*
* For more information on hooks, actions, and filters,
* {@link https://codex.wordpress.org/Plugin_API}
*/

function cosmetro_child_scripts() {
wp_enqueue_style( 'cosmetro-parent-style', get_template_directory_uri(). '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'cosmetro_child_scripts' );


// function woocommerce_single_product_summary_button() {
// echo '<a class="back_button" href="#" onclick="window.history.back()">Back</a>';
// }

// add_action( 'woocommerce_single_product_summary', 'woocommerce_single_product_summary_button', 11);

add_action('product_cat_add_form_fields', 'wh_taxonomy_add_new_meta_field', 10, 1);
add_action('product_cat_edit_form_fields', 'wh_taxonomy_edit_meta_field', 10, 1);
//Product Cat Create page

function wh_taxonomy_add_new_meta_field() {
?>
<div class="form-field">
<label for="wh_meta_title"><?php _e('Cover Image', 'wh'); ?></label>
<input type="file" name="" id="cover_image">
<p class="description"><?php _e('Enter a cover_image, <= 60 character', 'wh'); ?></p>
</div>
<div class="form-field">
<label for="wh_meta_desc"><?php _e('subName', 'wh'); ?></label>
<input type="text" name="" id="subName">
<p class="description"><?php _e('subName', 'wh'); ?></p>
</div>
<?php
}
//Product Cat Edit page
function wh_taxonomy_edit_meta_field($term) {
//getting term ID
$term_id = $term->term_id;
// retrieve the existing value(s) for this meta field.
$wh_meta_title = get_term_meta($term_id, 'wh_meta_title', true);
$wh_meta_subName = get_term_meta($term_id, 'wh_meta_subName', true);
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="wh_meta_title"><?php _e('Meta Title', 'wh'); ?></label></th>
<td>
<input type="file" name="cover_image" id="cover_image" value="<?php echo esc_attr($wh_meta_title) ? esc_attr($wh_meta_title) : ''; ?>">
<p class="description"><?php _e('Enter a meta title, <= 60 character', 'wh'); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="wh_meta_subName"><?php _e('subName', 'wh'); ?></label></th>
<td>
<input type="text" name="subName" id="subName" value="<?php echo esc_attr($wh_meta_subName) ? esc_attr($wh_meta_subName) : ''; ?>">
<p class="description"><?php _e('subName', 'wh'); ?></p>
</td>
</tr>
<?php
}
add_action('edited_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
add_action('create_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
// Save extra taxonomy fields callback function.
function wh_save_taxonomy_custom_meta($term_id) {
$wh_meta_title = filter_input(INPUT_POST, 'wh_meta_title');
$wh_meta_subName = filter_input(INPUT_POST, 'wh_meta_subName');
update_term_meta($term_id, 'wh_meta_title', $wh_meta_title);
update_term_meta($term_id, 'wh_meta_subName', $wh_meta_subName);
}









share|improve this question





























    0















    I have added a custom wordpress field via the following code, but I cannot save the new value for it when I click on edit. When I edit, the value always shows as empty. What am I doing wrong?



    <?php
    update_option( 'siteurl', 'http://2018.hellotreelb.com/luxin' );
    update_option( 'home', 'http://2018.hellotreelb.com/luxin' );
    /**
    *
    * @link https://codex.wordpress.org/Theme_Development
    * @link https://codex.wordpress.org/Child_Themes
    *
    * Functions that are not pluggable (not wrapped in function_exists()) are
    * instead attached to a filter or action hook.
    *
    * For more information on hooks, actions, and filters,
    * {@link https://codex.wordpress.org/Plugin_API}
    */

    function cosmetro_child_scripts() {
    wp_enqueue_style( 'cosmetro-parent-style', get_template_directory_uri(). '/style.css' );
    }
    add_action( 'wp_enqueue_scripts', 'cosmetro_child_scripts' );


    // function woocommerce_single_product_summary_button() {
    // echo '<a class="back_button" href="#" onclick="window.history.back()">Back</a>';
    // }

    // add_action( 'woocommerce_single_product_summary', 'woocommerce_single_product_summary_button', 11);

    add_action('product_cat_add_form_fields', 'wh_taxonomy_add_new_meta_field', 10, 1);
    add_action('product_cat_edit_form_fields', 'wh_taxonomy_edit_meta_field', 10, 1);
    //Product Cat Create page

    function wh_taxonomy_add_new_meta_field() {
    ?>
    <div class="form-field">
    <label for="wh_meta_title"><?php _e('Cover Image', 'wh'); ?></label>
    <input type="file" name="" id="cover_image">
    <p class="description"><?php _e('Enter a cover_image, <= 60 character', 'wh'); ?></p>
    </div>
    <div class="form-field">
    <label for="wh_meta_desc"><?php _e('subName', 'wh'); ?></label>
    <input type="text" name="" id="subName">
    <p class="description"><?php _e('subName', 'wh'); ?></p>
    </div>
    <?php
    }
    //Product Cat Edit page
    function wh_taxonomy_edit_meta_field($term) {
    //getting term ID
    $term_id = $term->term_id;
    // retrieve the existing value(s) for this meta field.
    $wh_meta_title = get_term_meta($term_id, 'wh_meta_title', true);
    $wh_meta_subName = get_term_meta($term_id, 'wh_meta_subName', true);
    ?>
    <tr class="form-field">
    <th scope="row" valign="top"><label for="wh_meta_title"><?php _e('Meta Title', 'wh'); ?></label></th>
    <td>
    <input type="file" name="cover_image" id="cover_image" value="<?php echo esc_attr($wh_meta_title) ? esc_attr($wh_meta_title) : ''; ?>">
    <p class="description"><?php _e('Enter a meta title, <= 60 character', 'wh'); ?></p>
    </td>
    </tr>
    <tr class="form-field">
    <th scope="row" valign="top"><label for="wh_meta_subName"><?php _e('subName', 'wh'); ?></label></th>
    <td>
    <input type="text" name="subName" id="subName" value="<?php echo esc_attr($wh_meta_subName) ? esc_attr($wh_meta_subName) : ''; ?>">
    <p class="description"><?php _e('subName', 'wh'); ?></p>
    </td>
    </tr>
    <?php
    }
    add_action('edited_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
    add_action('create_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
    // Save extra taxonomy fields callback function.
    function wh_save_taxonomy_custom_meta($term_id) {
    $wh_meta_title = filter_input(INPUT_POST, 'wh_meta_title');
    $wh_meta_subName = filter_input(INPUT_POST, 'wh_meta_subName');
    update_term_meta($term_id, 'wh_meta_title', $wh_meta_title);
    update_term_meta($term_id, 'wh_meta_subName', $wh_meta_subName);
    }









    share|improve this question



























      0












      0








      0








      I have added a custom wordpress field via the following code, but I cannot save the new value for it when I click on edit. When I edit, the value always shows as empty. What am I doing wrong?



      <?php
      update_option( 'siteurl', 'http://2018.hellotreelb.com/luxin' );
      update_option( 'home', 'http://2018.hellotreelb.com/luxin' );
      /**
      *
      * @link https://codex.wordpress.org/Theme_Development
      * @link https://codex.wordpress.org/Child_Themes
      *
      * Functions that are not pluggable (not wrapped in function_exists()) are
      * instead attached to a filter or action hook.
      *
      * For more information on hooks, actions, and filters,
      * {@link https://codex.wordpress.org/Plugin_API}
      */

      function cosmetro_child_scripts() {
      wp_enqueue_style( 'cosmetro-parent-style', get_template_directory_uri(). '/style.css' );
      }
      add_action( 'wp_enqueue_scripts', 'cosmetro_child_scripts' );


      // function woocommerce_single_product_summary_button() {
      // echo '<a class="back_button" href="#" onclick="window.history.back()">Back</a>';
      // }

      // add_action( 'woocommerce_single_product_summary', 'woocommerce_single_product_summary_button', 11);

      add_action('product_cat_add_form_fields', 'wh_taxonomy_add_new_meta_field', 10, 1);
      add_action('product_cat_edit_form_fields', 'wh_taxonomy_edit_meta_field', 10, 1);
      //Product Cat Create page

      function wh_taxonomy_add_new_meta_field() {
      ?>
      <div class="form-field">
      <label for="wh_meta_title"><?php _e('Cover Image', 'wh'); ?></label>
      <input type="file" name="" id="cover_image">
      <p class="description"><?php _e('Enter a cover_image, <= 60 character', 'wh'); ?></p>
      </div>
      <div class="form-field">
      <label for="wh_meta_desc"><?php _e('subName', 'wh'); ?></label>
      <input type="text" name="" id="subName">
      <p class="description"><?php _e('subName', 'wh'); ?></p>
      </div>
      <?php
      }
      //Product Cat Edit page
      function wh_taxonomy_edit_meta_field($term) {
      //getting term ID
      $term_id = $term->term_id;
      // retrieve the existing value(s) for this meta field.
      $wh_meta_title = get_term_meta($term_id, 'wh_meta_title', true);
      $wh_meta_subName = get_term_meta($term_id, 'wh_meta_subName', true);
      ?>
      <tr class="form-field">
      <th scope="row" valign="top"><label for="wh_meta_title"><?php _e('Meta Title', 'wh'); ?></label></th>
      <td>
      <input type="file" name="cover_image" id="cover_image" value="<?php echo esc_attr($wh_meta_title) ? esc_attr($wh_meta_title) : ''; ?>">
      <p class="description"><?php _e('Enter a meta title, <= 60 character', 'wh'); ?></p>
      </td>
      </tr>
      <tr class="form-field">
      <th scope="row" valign="top"><label for="wh_meta_subName"><?php _e('subName', 'wh'); ?></label></th>
      <td>
      <input type="text" name="subName" id="subName" value="<?php echo esc_attr($wh_meta_subName) ? esc_attr($wh_meta_subName) : ''; ?>">
      <p class="description"><?php _e('subName', 'wh'); ?></p>
      </td>
      </tr>
      <?php
      }
      add_action('edited_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
      add_action('create_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
      // Save extra taxonomy fields callback function.
      function wh_save_taxonomy_custom_meta($term_id) {
      $wh_meta_title = filter_input(INPUT_POST, 'wh_meta_title');
      $wh_meta_subName = filter_input(INPUT_POST, 'wh_meta_subName');
      update_term_meta($term_id, 'wh_meta_title', $wh_meta_title);
      update_term_meta($term_id, 'wh_meta_subName', $wh_meta_subName);
      }









      share|improve this question
















      I have added a custom wordpress field via the following code, but I cannot save the new value for it when I click on edit. When I edit, the value always shows as empty. What am I doing wrong?



      <?php
      update_option( 'siteurl', 'http://2018.hellotreelb.com/luxin' );
      update_option( 'home', 'http://2018.hellotreelb.com/luxin' );
      /**
      *
      * @link https://codex.wordpress.org/Theme_Development
      * @link https://codex.wordpress.org/Child_Themes
      *
      * Functions that are not pluggable (not wrapped in function_exists()) are
      * instead attached to a filter or action hook.
      *
      * For more information on hooks, actions, and filters,
      * {@link https://codex.wordpress.org/Plugin_API}
      */

      function cosmetro_child_scripts() {
      wp_enqueue_style( 'cosmetro-parent-style', get_template_directory_uri(). '/style.css' );
      }
      add_action( 'wp_enqueue_scripts', 'cosmetro_child_scripts' );


      // function woocommerce_single_product_summary_button() {
      // echo '<a class="back_button" href="#" onclick="window.history.back()">Back</a>';
      // }

      // add_action( 'woocommerce_single_product_summary', 'woocommerce_single_product_summary_button', 11);

      add_action('product_cat_add_form_fields', 'wh_taxonomy_add_new_meta_field', 10, 1);
      add_action('product_cat_edit_form_fields', 'wh_taxonomy_edit_meta_field', 10, 1);
      //Product Cat Create page

      function wh_taxonomy_add_new_meta_field() {
      ?>
      <div class="form-field">
      <label for="wh_meta_title"><?php _e('Cover Image', 'wh'); ?></label>
      <input type="file" name="" id="cover_image">
      <p class="description"><?php _e('Enter a cover_image, <= 60 character', 'wh'); ?></p>
      </div>
      <div class="form-field">
      <label for="wh_meta_desc"><?php _e('subName', 'wh'); ?></label>
      <input type="text" name="" id="subName">
      <p class="description"><?php _e('subName', 'wh'); ?></p>
      </div>
      <?php
      }
      //Product Cat Edit page
      function wh_taxonomy_edit_meta_field($term) {
      //getting term ID
      $term_id = $term->term_id;
      // retrieve the existing value(s) for this meta field.
      $wh_meta_title = get_term_meta($term_id, 'wh_meta_title', true);
      $wh_meta_subName = get_term_meta($term_id, 'wh_meta_subName', true);
      ?>
      <tr class="form-field">
      <th scope="row" valign="top"><label for="wh_meta_title"><?php _e('Meta Title', 'wh'); ?></label></th>
      <td>
      <input type="file" name="cover_image" id="cover_image" value="<?php echo esc_attr($wh_meta_title) ? esc_attr($wh_meta_title) : ''; ?>">
      <p class="description"><?php _e('Enter a meta title, <= 60 character', 'wh'); ?></p>
      </td>
      </tr>
      <tr class="form-field">
      <th scope="row" valign="top"><label for="wh_meta_subName"><?php _e('subName', 'wh'); ?></label></th>
      <td>
      <input type="text" name="subName" id="subName" value="<?php echo esc_attr($wh_meta_subName) ? esc_attr($wh_meta_subName) : ''; ?>">
      <p class="description"><?php _e('subName', 'wh'); ?></p>
      </td>
      </tr>
      <?php
      }
      add_action('edited_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
      add_action('create_product_cat', 'wh_save_taxonomy_custom_meta', 10, 1);
      // Save extra taxonomy fields callback function.
      function wh_save_taxonomy_custom_meta($term_id) {
      $wh_meta_title = filter_input(INPUT_POST, 'wh_meta_title');
      $wh_meta_subName = filter_input(INPUT_POST, 'wh_meta_subName');
      update_term_meta($term_id, 'wh_meta_title', $wh_meta_title);
      update_term_meta($term_id, 'wh_meta_subName', $wh_meta_subName);
      }






      wordpress custom-fields






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 16:03









      Josh Mein

      21.6k106881




      21.6k106881










      asked Nov 14 '18 at 13:20









      eddy1010eddy1010

      12




      12
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301200%2fadd-edit-custom-fields-in-wordpress%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301200%2fadd-edit-custom-fields-in-wordpress%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine