JackDavis
JackDavis

Reputation: 127

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 );

Upvotes: 1

Views: 4327

Answers (3)

Dmitry G
Dmitry G

Reputation: 93

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

Upvotes: 1

Dmitry G
Dmitry G

Reputation: 93

function include() can includes only php/html files for execute, without GET or POST parametrs.

Upvotes: 1

VIVEK SEDANI
VIVEK SEDANI

Reputation: 407

Use include( get_template_directory() . '/filetoinclude.php' ); It will work.

Upvotes: 1

Related Questions