Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

Hook into the admin_init action...

add_action('admin_init', 'fetch_all_companies');

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

note:

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

 
discard

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.