Skip to main content
4 of 6
added 113 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:

I need to check if any of my custom-post types called "members" have been saved. The template I'm using to display the posts is single-members.php.

If the post has been saved, then on my single-members.php template, I need to call get_template_part('geocode'); - but only if the post has been saved.

I DON'T WANT THIS TO HAPPEN IN THE ADMIN AREA, THIS NEEDS TO HAPPEN FRONT-END OF THE WEBSITE. OBVIOUSLY THE ONLY THING I WANT TO DO IN THE ADMIN AREA IS TO CLICK PUBLISH/UPDATE.

Rob
  • 1.4k
  • 13
  • 41
  • 68