简体   繁体   中英

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

函数include()只能包含要执行的php / html文件,而没有GET或POST参数。

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM