• How do I save term?

    function functiondolarfull( $post_id ) {
            $terms10 = '';
    
        $getslugid = wp_get_post_terms( $post_id, 'my_taxonomy' ); 
        $slugs = implode(', ',wp_list_pluck($getslugid,'slug'));
            ?>
    
            <div class="dolarfull-label">
                <label>Dolar Full</label>
            </div>
    
            <div class="dolarfull-fields">
                <input type="text" name="testgo1" value="<?php echo $slugs; ?>">
            </div>
            <?php
        }
    
        add_action( 'ACTIONHOOKDOLARFULL', 'functiondolarfull', 10, 3 );

    the top is ok

    the problem is on the bottom

    function update_my_function( $post_id ) {
        if ( isset( $_POST['my_custom_field'] ) ) {
            wp_update_term(10000000000000000, 'my_taxonomy', array('name' => $_POST['my_custom_field']));
        }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Please do not bump your topic with redundant information. Not only does it not have the effect you think it does, it makes your topic less visible to the people in the best position to help you. These people rely on the “No Replies” filter to find people still needing help. By bumping, your topic falls off of this list. I’m removing your bump post from public view.

    What are you actually trying to do? Assign an existing term to a post? Alter the data of an existing term? Add a new term, and maybe also assign to a post?

    Thread Starter manoodin

    (@manoodin)

    Not to edit or delete : (

    Moderator bcworkz

    (@bcworkz)

    But updating a term is essentially editing the term. I don’t understand.

    Assuming all the provided parameters are correct, wp_update_term() will work as expected. But without sanitizing and validating $_POST[‘my_custom_field’], you cannot really be sure the passed value is correct. You may use the raw data unchecked during development, but be sure you are providing valid data. Even then, it’s probably a good idea to run the value through stripslashes().

    Hard coding the ID will work as long as it’s the right ID, but in practice you should be getting the ID dynamically. How that is done depends on what term you are trying to update.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I save term?’ is closed to new replies.