I am trying to run the following function anytime a wordpress “Jobs” custom post is published. The code works (lines 2-7) when it is placed in my theme template, but it only runs when the post is viewed. I want the code to run when the post is published, and so I have tried adding the code in a function inside my functions.php, but nothing is happening when each custom post is published. Any suggestions?
function indeedgeo(){
$indeedgeo = get_post_meta($post>ID, indeedgeo, true);
$indeedgeos=explode(' ',$indeedgeo);
$_jr_geo_latitude = $indeedgeos[0];
$_jr_geo_longitude = $indeedgeos[1];
update_post_meta($post->ID, _jr_geo_latitude, $_jr_geo_latitude);
update_post_meta($post->ID, _jr_geo_longitude, $_jr_geo_longitude);
}
add_action('publish_Jobs', 'indeedgeo');
You should hook into one of the three actions;
that are run when a post is either saved, or has its status updated. Something like the following should do the trick.
http://codex.wordpress.org/Plugin_API/Action_Reference