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 am using function query() and get_results in my plugin code but, it gives me this error: "Fatal error: Call to a member function query() on a non-object". I have this lines of code:

class Dynamic_form {

    function product_category(){
        global $wpdb;
        $TablePressData = $wpdb->query(
                "
                    SELECT post_title
                    FROM $wpdb->posts
                    WHERE post_type = 'tablepress_table'
                "
            );
        return print_r($TablePressData);
    }
}

I am using version 3.6.1 (My client already using the version so I'm afraid of updating it).

share|improve this question
3  
Where/when do you call this function? –  Milo Nov 21 '13 at 14:43
    
In the index file of my plugin; plugin/myfolder/index.php. –  Edion Larosa Nov 22 '13 at 16:26
    
actually this is already solved. I add this function. if(!class_exists("RGForms")){ for ( $i = 0; $i < $depth = 10; $i++ ) { $wp_root_path = str_repeat( '../', $i ); if ( file_exists("{$wp_root_path}wp-load.php" ) ) { require_once("{$wp_root_path}wp-load.php"); require_once("{$wp_root_path}wp-admin/includes/admin.php"); break; } } //redirect to the login page if user is not authenticated auth_redirect(); } –  Edion Larosa Nov 22 '13 at 16:27
    
Your issue is clear now - you can't load plugin or template files directly because the WordPress environment is not loaded. You should use a rewrite endpoint to allow direct access to your plugin rather than requiring wp-load.php, which will make your code less portable. Any plugin which does that would be rejected from the WordPress.org plugin repository. –  Milo Nov 22 '13 at 16:35

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.