Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to run a script when a user publishes / updates a post.

I am using the filter: wp_insert_post_data

The problem I am having is the script is a php file outside of WordPress but on the same site (It works fine if i go direct to it) that just needs to be run. I tried to include the file using the filter but that stopped the post being updated for some reason.

This is my current code:

function updateFeed( $data , $postarr) {
   include 'jobsfeed.php';  
   return $data;
}

add_filter( 'wp_insert_post_data' , 'updateFeed' , '99', 2 );

Is there any way to be able to run this script?

EDIT:

It does seem teh file is being run but for some odd reason it is not outputting the custom field values. It is a simple php file with a loop using wp_query and it works fine when I go direct to it. - any ideas what it could be?

EDIT:

Figured out why teh custom post types were not working i had to change how the script retrievd an id. Now I have one final thing to fix for some reason when the script runs when a page is edited the xml output by the script is the previous save data. SO it means i have to press save twice to make my new edits appear. Is it getting the revisions or being triggered too early perhaps?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

It looks like it could be because the filter cannot find the include file.

Try using:

include( ABSPATH. "/path/to/file/jobsfeed.php" )
share|improve this answer
    
I have tried that as well as trying ` include( $_SERVER['DOCUMENT_ROOT']. "/wp-content/plugins/bb-jobs/jobsfeed.php" );` i get no errors and I think that the file is being run now but it seems the file that is running ( a page that has the loop on it to create an xml file) it seems like it only updates the new edits and blanks everything else which is very odd. The file being run is simply a loop with require_once wp-load.php and works fine if i go direct to the file. –  Lee Aug 5 '11 at 13:46
    
Don't require wp-load.php. You're already in the WordPress context, you don't need to load the file again. –  Otto Aug 5 '11 at 15:36
    
Hi Otto, it needs it in this case as the script is run outside of WordPress as well as using this method but maybe I could check for this anhd thennot load it if within WordPress. –  Lee Aug 5 '11 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.