Skip to main content
3 of 6
added 119 characters in body
Rob
  • 1.4k
  • 13
  • 41
  • 68

Do action on publish or update?

Is there a way to only do a section of code on a template if the post has just been published or updated?

So for instance, I only want to do this ONCE:

$company = get_field('company_name');
$address = get_field('address');
$city = get_field('city');
$post_code = get_field('post_code');

When a post is published or updated. What do I need to wrap around that code?

UPDATE:

In my functions file I need to add the hook:

function my_data_update () {
 $company = get_template_part('geocode');
}
add_action('publish_post', 'my_data_update');
add_action('save_post', 'my_data_update');

On my single-members.php template I need to check whether the post was saved, if it was I then need to show the "geocode" part of the template.

Rob
  • 1.4k
  • 13
  • 41
  • 68