Home Forums Backend Issues (wp-admin) Add custom field value to multiple posts at once


Add custom field value to multiple posts at once

  • Hi there,

    Big fan of ACF here – great plugin! I have a quick question:

    We’re using ACF for a WordPress-based cell phone retailer website. Phones are controlled as posts, and we have all the phone specs, etc. entered as custom fields.

    What I’m trying to do is write a plugin that will function as a “sale manager” – The idea is that in a new back-end tab they will be able to select either individual products or whole categories for sale treatment.

    Is there a way that I can apply a custom field value to multiple posts at once? For instance if I’ve got a boolean “Sale” field for every post, or a numerical “Discount %” field, can I arbitrarily change the value of that field across several posts at once from a central admin panel?

    Any help much appreciated.


    -=- EDIT: -=-

    I have since found the “Options Page” addon which would handle my requirement of having a new “Sale Manager” page with its own custom fields.

    So here’s my thought process – I would create a Post Object field on the options page, and then write a script to update the Sale custom field for each selected post object with a given value.

    Can anyone confirm/refute the possibility of this process? Thanks!

  • Hi @cosmic

    Can you please elaborate more on field setup you are talking about?
    I can make out that there is a post_object field on the options page, and also a true_false field on each post. Is this correct?

    And you want this true_false to reflect the selection made on the options page?
    Do you want both the true_false and the post_object field to update the same value?


  • Hi there, thanks for your response!

    To clarify, now I have set up an Options Page with a repeater field called “Sales”. This repeater contains three fields:

    “Sale type” – Select – Fixed $ amount / Fixed % discount
    “Discount” – Number – Amount of discount
    “Devices” – Post Object – Selects applicable posts

    Then, for the main device post type, those three fields will be duplicated. Now what I need is a way to pass those values to the fields in the posts chosen. I understand I can use update_field() – I’m thinking I can write a loop that collects the post IDs from the post object field and then uses update_field() to apply the values selected to those posts.

    That seems to make sense- but then I’m not sure how I would even call the update_field() action or where that would live. I am far from an expert in WordPress plugin coding, so any help is much appreciated!


  • P.S. – It occurs to me that I may be able to use a different methodology here-

    We have pages on which category posts are displayed – technically in the loop on those pages, for each post I can check if that post has been selected for a sale, and do whatever I want to the post formatting then – correct? If you could point me in the right direction on how to approach either of these methods I’d greatly appreciate it. Thanks again!

  • This is no longer relevant- delete if you wish

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

The topic ‘Add custom field value to multiple posts at once’ is closed to new replies.