Writing my first function in functions.php
-
Hi all,
I wrote some simple code to manipulate some custom fields (//geo splitting code section), which works perfectly when I put it in my single template. The issue is the code only runs once someone visits the page, and I need the code to run when the post goes live because the custom fields affect how the post displays in the search results. So instead I’m trying to add the code as a function in functions.php that runs whenever a post is saved.
Please note that these posts are automatically imported from a RSS feed into the custom post type “Jobs”.
//Indeedgeo function indeedgeo_save_post($post_id, $post){ //determine post type if(get_post_type( $post_id ) == 'Jobs'){ //geo splitting code $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('save_post', 'indeedgeo_save_post', 1, 2);
Unfortunately nothing seems to be happening and I have no idea why. Can anyone point me in the right direction?
Thanks very much for any help.
- The topic ‘Writing my first function in functions.php’ is closed to new replies.