Home Forums General Issues Updating custom field values


Updating custom field values

  • Hello, I created slider with 5 post, and there is select field to select on which position (1 – 5) post will appear in the slider, so basically they are ordering by numbers. Is there any way to automatically update value of other posts after post is published/updated? For example if on new post slider position is selected for position 2, other posts which have position 3,4,5 etc will automatically update value for +1 or if someone select position 5, position that was on 5th position will update value 6.


  • There isn’t enough information to understand what you’re trying to accomplish, at least there’s not enough for me to figure it out, and that’s probably why you’re not getting any replies. Please provide a better explanation of what you are attempting to do.

  • Hi John,

    Thank you for a reply. I will try to explain what I’m trying to accomplish.. Well I want to sort post by custom acf field. So ordering should be by number value from acf field (1,2,3,4,5 etc) and this is something that is easy. Now is the tricky part. If I want to publish new post and enter value in acf field for exmpale “3”, is there any way to change values for posts that have values 3 and 4 by +1 so post that had value 3 now has 4, and post that had value 4 now has value 5?


  • I don’t have code for you but what you’d have to do is this.

    Create an acf/save_post filter

    In this filter you would get the value of the field saved in this post then you would do a query of other posts that have the same value and if you find one they you’d update the acf field on that other post. You would need to continue doing this until you don’t fond and posts with the same value.

  • Wouldn’t it be easier to have a global slider option instead of setting this for every post? You could use a repeater field to add new post_id’s to your slider and make this field visible within the option page. The only thing to code would be a populate_field filter to provide all avaible posts for the slider settings.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Updating custom field values’ is closed to new replies.