I added an extra field (dropdown list with select options), when the user creates or edits a category from the WordPress dashboard. I am also able to store the selected value in the wp_termmeta table. However, I need to display the selected value from the dropdown list after page refresh. I am using the functions get_term_meta() and update_post_meta(), however get_term_meta() always returns false and I cannot assign a selected value for any of the options:

function changePostOrder(){

    $post_order = get_term_meta($_POST['tag_ID'], 'post-order', true);

    var_dump($post_order); // $post_order returns false, while it should return oldest or newest

    <tr class="form-field">
        <th scope="row" valign="top"><label for="post-order"><?php _e('Post Order'); ?></label></th>

        <select name="post-order" id="post-order">
            <option <?php if ($post_order == 'oldest') { ?>selected="true" <?php }; ?>value="oldest">oldest</option>
            <option <?php if ($post_order == 'newest') { ?>selected="true" <?php }; ?>value="newest">newest</option>


add_action ( 'edit_category_form_fields', 'changePostOrder');

As a result, after page refresh the dropdown list is again the same (oldest is selected), even though in the database the meta_value column is "newest". Am i doing something wrong? I am using the same approach as suggested in the second answer here.

  • You should be using$_GET, not $_POST. Sep 28, 2019 at 2:31
  • This solved the issue! Thank you very much.
    – Badan
    Sep 29, 2019 at 16:21


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.