I want to ask if there is a hook for executing php inside the admin area, my problem is I'm trying to do the get_posts wordpress function inside a popup frame using the thickbox jQuery plugin, using an anchor, and I linked this anchor to a page contains my code

I do the main function in the functions.php file which is

function fetch_all_companies() {
$companies_args = array(
    'numberposts' => -1,
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'company',
    'post_status' => 'publish'
$companies = get_posts($companies_args);
return $companies;}

when executing this function inside the admin panel I got this error

Fatal error: Call to undefined function fetch_all_companies()

any ideas ???


Hook into the admin_init action...

add_action('admin_init', 'fetch_all_companies');

function fetch_all_companies() {
    //do something here...


What file are you running your fetch_all_companies() function from and where is it located (the path to the file)? Its likely the WordPress environment is not loaded on the destination file which is why your function appears to be undefined.

  • Not working, The same error – Mohamed Gaber Aug 15 '12 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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