Home Forums General Issues Update custom field value of other posts via a message field


Update custom field value of other posts via a message field

  • Hi,

    I have an acf-options page with a message field that displays a list of all the posts fitting a certain criteria. The result would be displayed in a table – one post per row, with a checkbox in one of the column.

    When saving the options page, I would like to update the value of specific custom field in all the posts that have the checkbox checked***

    Is this doable with only PHP and JS, or will this require Ajax ?
    Is this even doable with a message field, or I am tackling this issue the wrong way ?

    ***the value of the checkbox itself won’t have to be saved – the checkbox just indicates the action to do on a specific custom field of the post. Actually it doesn’t even have to be a checkbox. Could be a simple div, that would have its css class or .html() changed with JS on click.

    (fyi, what i want to achieve is :
    if the checkbox is checked => the value of a custom field is changed in the corresponding post => the post won’t appear anymore in the options page (because the php query filters it out)

  • Most likely I would use a repeater to do the same thing, unless I was planning on showing a very large number of rows.

    You can do this with PHP. You would need to give your checkbox field a unique name. The you would need to create PHP that runs when the page is submitted to get your checkbox from $_POST and update the corresponding posts. Yes it is doaable. You can use an acf/save_post action.

    As long as it’s not an ACF field and has a unique name it won’t be save anywhere by default.

  • Thank you very much !
    Hmm, I wouldn’t know how to proceed using a repeater, I’d have to look into it. What would be the advantage compared to a simple message field with a php query?

  • The advantage for me is having the ACF fields submitted and using those rather than a custom input. The other advantage for me is not building a table in a message field.

    But, it would not reduce work. I’d have to dynamically load the ACF repeater. I’d have to make all the fields except the checkbox readonly. I still have to do all the processing. And then I would need to delete the repeater data that ACF saved after I was done processing. In the long run this would probably be more work to be honest. I’d also need to weigh that against I needed this and the time I have available to get the job done. And like I said, how many posts would be shown. Make a repeater too long and bad things can happen so I’d have to look at the possibility of the repeater growing too large.

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

You must be logged in to reply to this topic.