WordPress.org

Ready to get started?Download WordPress

Forums

Writing my first function in functions.php (3 posts)

  1. Nick5a1
    Member
    Posted 2 years ago #

    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.

  2. Nick5a1
    Member
    Posted 2 years ago #

    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

  3. Peter_L
    Member
    Posted 2 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic