WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ???

share|improve this question

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.

share|improve this answer
Not working, The same error – Mohamed Gaber Aug 15 '12 at 9:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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