Title: Writing my first function in functions.php
Last modified: August 20, 2016

---

# Writing my first function in functions.php

 *  [Nick5a1](https://wordpress.org/support/users/nick5a1/)
 * (@nick5a1)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/writing-my-first-function-in-functionsphp/)
 * 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.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Nick5a1](https://wordpress.org/support/users/nick5a1/)
 * (@nick5a1)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/writing-my-first-function-in-functionsphp/#post-2729302)
 * This doesn’t seem to be working because the posts are imported from RSS via the
   AutoBlogged plugin, which I believe is using XML-RPC
 *  [Peter_L](https://wordpress.org/support/users/peter_l/)
 * (@peter_l)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/writing-my-first-function-in-functionsphp/#post-2729324)
 * > 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.
 * This doesn’t make sense. Could you describe the problem again with a link?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Writing my first function in functions.php’ is closed to new replies.

## Tags

 * [add_action](https://wordpress.org/support/topic-tag/add_action/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Peter_L](https://wordpress.org/support/users/peter_l/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/writing-my-first-function-in-functionsphp/#post-2729324)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
