Can I Include php in functions.php? – WordPress

I need to call custom php script when I publish new post in WP. This function works, but include not. It is not included. Can it be working or is there any other way to include php file in functios.php?

function new_post_caller( $ID, $post )  {

    include( get_template_directory() . 'call_new_post.php?ID='.$ID.'' );

}

add_action( 'publish_mypost', 'new_post_caller', 10, 2 );

Related posts

Leave a Reply

3 comments

  1. If you want to include script and pass a parameter to him, you can create function in including script and use construction like this:

    some script to include (file.php):

    function some_function ($id) {
     //some code, using $id
    }
    

    and calling file.php and pass a parameter:

    include('file.php'); 
    some_function(23);
    

    Function include() simply adds the code from including file to the file where the function was originated
    http://php.net/manual/en/function.include.php