• Resolved bodry24

    (@bodry24)


    Hello,
    I’m beginning wp coding, and my level in english is not the top but I’ll try to explain my problem like this. I’m creating a custom post meta which is updated once the post is opened. I use the following row for the action
    update_post_meta($post_id,'post_viewed',$new_value)
    This code seems to work well until I remark when the current post meta value is updated, others post meta values are also updated. I’m working in my custom theme ‘single.php’ file.
    Please Help Me. Thk

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    There should not be any reason that code would update other meta values. There is a slight possibility that some other update code has hooked into the action “update_post_meta”. In such a situation, any time the update_post_meta() function is called, the code hooked to the action “update_post_meta” also runs.

    I don’t fully understand the situation where you are experiencing the problem. You said “…until I remark when the current post meta value is updated.” Please explain what you are doing when you “remark”, I don’t know what that means in this context.

    Thread Starter bodry24

    (@bodry24)

    Thank you for the answer. I found a piece of code which make it work well now

    add_action( 'init','remove_some_actions' );
    
    function remove_some_actions(){
       remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 2 );
    }

    I put this in my function file and my incrementation is working as it is supposed to work.
    Thank you

    Thread Starter bodry24

    (@bodry24)

    Thanks

    Jon Brain

    (@brainjonbrain)

    I had the same problem as @bodry24 – update_post_meta() updating the meta data for the post I wanted it to update and – incorrectly – updating the meta data for its next adjacent one as well.

    Thanks for the solution!

    Wait what? I use update_post_meta quite a bit. What is meant by i’ts next adjacent one’? Are you saying that a post other than the post id passed to update_post_meta is being updated or are you saying that an entry in the same post id with the same key name is also being updated?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘update_post_meta update more than one post meta’ is closed to new replies.