I want to include different file in function.php file of my wordpress theme based on different custom post type using admin_init hook. Is it possible?
I found the solution and added as an answer.
add_action('admin_init', 'include_files');
function include_files()
{
global $pagenow;
if ('post.php' == $pagenow && isset($_GET['post']) )
{
$post_type = get_post_type(esc_attr($_GET['post'])) ;
}
else if ('post-new.php' == $pagenow && isset($_GET['post_type']) )
{
$post_type = $_GET['post_type'];
}
if($post_type == 'custom_post'){
include_once('file1.php');
}else{
include_once('file2.php');
}
}
Exactly what are you trying to achieve here? You can use php functions in your functions.php file and call the functions up in your template files.
I.e. for post-listing or whatever you have the custom posts named, you should be calling the functions from there.
Although, your information is a bit vague and i can't figure out what you are trying to do. However, your approach is bad and i'm 100% sure there's a better way to do it.
Please go to http://codex.wordpress.org/ for detailed reference - anything you need is there, just learn to understand the information presented.
Hope it helps