Support

Account

Home Forums Add-ons Options Page Pass Field Value From Options Page to All Posts In a Category

Solving

Pass Field Value From Options Page to All Posts In a Category

  • Just wondering if it’s possible to pass an updated numeric field value from an options page to a numeric acf field in all posts in a specific category?

    At the moment in the (blocks) template for the category I am using a php snippet to retrieve the value from the options page. This works absolutely fine but I’m interested to find if there is a way to pass the update as an alternative method.

    Ideas appreciated.

    Thanks.

  • It would be possible, but it would not be efficient.

    You would create an acf/save_post action, you would check that the options page is being updated by checking that the post ID = “options”. The you would need to do a WP_Query to get all the post IDs for all of the posts in the category, loop over the list of posts and call the ACF function update_field() for each post.

  • How inefficient – would it be performance degrading? It would be for a category that lists products – a finite number of say up to 30, with a periodic update every week or so. But the options page could have multiple fields that would need updates passing…

    Anyway, it sounds outside the scope of what I want to focus on – I tend to get a result and then try and find another way to see if I can improve it… Currently I retrieve values in a template using the standard php snippets provided by ACF documentation. It works so I should stick with that.

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

You must be logged in to reply to this topic.