Title: salvatorericcardi's Replies | WordPress.org

---

# salvatorericcardi

  [  ](https://wordpress.org/support/users/richdeveloper/)

 *   [Profile](https://wordpress.org/support/users/richdeveloper/)
 *   [Topics Started](https://wordpress.org/support/users/richdeveloper/topics/)
 *   [Replies Created](https://wordpress.org/support/users/richdeveloper/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/richdeveloper/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/richdeveloper/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/richdeveloper/engagements/)
 *   [Favorites](https://wordpress.org/support/users/richdeveloper/favorites/)

 Search replies:

## Forum Replies Created

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/users/richdeveloper/replies/page/2/?output_format=md)
[→](https://wordpress.org/support/users/richdeveloper/replies/page/2/?output_format=md)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[YITH WooCommerce Recover Abandoned Cart] Manual e-mail hasn’t arrived yet](https://wordpress.org/support/topic/manual-e-mail-hasnt-arrived-yet/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/manual-e-mail-hasnt-arrived-yet/#post-11565190)
 * When I click on send email it isn’t sent also if I have an abandoned cart.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/page/2/#post-11545320)
 * Update: I used `var_dump()` function on `$wpdb` global variable and it returns`
   null`. Why?
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/page/2/#post-11544014)
 * I’m sorry I did a lot of confusion, the error is: **Call to a member function
   insert() on null** that the function `$wpdb->insert();` returns.
 * Now, this is my array: `Array ( [title] => Huqvarna 610 cross blocco motore [
   description] => Vendo blocco motore husqvarna 610 cross tenuto di scorta sempre
   in magazzino usato pochissimo perfetto [locale] => Riccione [timestamp] => Oggi,
   19:15 [price] => 500 € [ad_type] => 1 )` and this is my code:
 *     ```
       <?php
   
       class The_Crawler {
   
           public function __construct() { }
   
           public static function get_classifieds( $urls ) {
   
               global $wpdb;
   
               $dom_document = new DOMDocument();
   
               foreach($urls as $url) {
   
                   if( ! function_exists( 'wp_remote_request' ) ) {
   
                       $html = file_get_contents( $url );
                       $dom_document->loadHTML( $html );
   
                   } else {
   
                       $response = wp_remote_request( $url );            
                       $body = wp_remote_retrieve_body( $response ); 
                       $dom_document->loadHTML( $body );
   
                   } 
   
                   $li_elements = $dom_document->getElementsByTagName( 'li' );
   
                   foreach( $li_elements as $li_element ) {
   
                       $pattern = '/item\sresult/';
                       $class = $li_element->getAttribute( 'class' );
   
                       if( preg_match( $pattern, $class ) ) {
   
                           $classified = [];
   
                           $img_elements = $li_element->getElementsByTagName( 'img' );
                           $h3_elements = $li_element->getElementsByTagName( 'h3' );
                           $h4_elements = $li_element->getElementsByTagName( 'h4' );
                           $p_elements = $li_element->getElementsByTagName( 'p' );
   
                           foreach( $h3_elements as $h3_element) {
   
                               $h3_class = $h3_element->getAttribute( 'class' );
   
                               if( $h3_class == 'title' ) {
   
                                   $classified['title'] = $h3_element->nodeValue;
                                   // echo "<h3>$h3_element->nodeValue</h3>";
   
                               }
   
                           }
   
                           foreach( $img_elements as $img_element) {
   
                               $src = $img_element->getAttribute( 'src' );
   
                               if( strpos( $src, 'img' ) && ! strpos( $src, 'no-img' ) ) {
   
                                   $classified['src'] = $src;
                                   // echo "<img src='$src' />";
   
                               }
   
                           }
   
                           foreach( $p_elements as $p_element) {
   
                               $p_class = $p_element->getAttribute( 'class' );
   
                               if( $p_class == 'description' ) {
   
                                   $classified['description'] = $p_element->nodeValue;
                                   // echo "<p>$p_element->nodeValue</p>";
   
                               } elseif( $p_class == 'locale' ) {
   
                                   $classified['locale'] = $p_element->nodeValue;
                                   // echo "<p><strong>$p_element->nodeValue</strong></p>";
   
                               } elseif( $p_class == 'timestamp' ) {
   
                                   $classified['timestamp'] = $p_element->nodeValue;
                                   // echo "<p>$p_element->nodeValue</p>";
   
                               }
   
                           }
   
                           foreach( $h4_elements as $h4_element) {
   
                               $h4_class = $h4_element->getAttribute( 'class' );
   
                               if( $h4_class == 'price' ) {
   
                                   $classified['price'] = $h4_element->nodeValue;
                                   // echo "<h4>$h4_element->nodeValue</h4>";
   
                               }
   
                           }
   
                           $classified['ad_type'] = 1;
                           print_r($classified);
                           $query = $wpdb->insert( 'wp_classifieds', $classified );
                           echo $query;
   
                       }
   
                   }
   
               }
   
           }
   
       }
   
       $urls = [
           'https://www.kijiji.it/motori/moto-e-scooter/',
           'https://www.kijiji.it/elettronica/'
       ];
   
       The_Crawler::get_classifieds( $urls );
       ```
   
 * The query passed to insert function isn’t null how can you see in the array result
   above, but the error says that a member passed to the function is null: why? 
   Didn’t I understand something?
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/page/2/#post-11537377)
 * Ok, I repeat myself until we get to the solution: above there is the code that
   it must call $wpdb global variable to do a query into the database. I can do 
   it also with PHP function but if I’m using WordPress I want to use it for coding.
   Now, if I call the $wpdb variable like global into my custom class of the boilerplate
   plugin, PHP functions work but not the same of WordPress because it isn’t loaded
   by the plugin. So, how can the plugin load WordPress core? Just so I can use 
   the WordPress function and in another solution.
 * Finally, if you give me an email I can share to you my plugin code so it’s easier.
   Thanks 🙂
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/#post-11533374)
 * Ok, I understand. How can you see I use more WP Functions, but none of this works
   because WP isn’t loaded. So I have to include or require wp-load.php, but how
   the other plugins do?
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/#post-11526347)
 * Ok I understand just so far that I use this global variable out of WordPress 
   environment so it returns null. However now the question is: how can I use this
   global variable out of WordPress environment? Have I to include my function into
   an init hook? Or is there a ways to include $wpdb? I’m searching on the internet
   but probably my search is wrong.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[YITH WooCommerce Recover Abandoned Cart] Manual e-mail hasn’t arrived yet](https://wordpress.org/support/topic/manual-e-mail-hasnt-arrived-yet/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/manual-e-mail-hasnt-arrived-yet/#post-11525659)
 * No, any error message. I would like to use your plugin but so it’s very difficult.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/#post-11524063)
 * Ok [@diondesigns](https://wordpress.org/support/users/diondesigns/) and [@joyously](https://wordpress.org/support/users/joyously/)
   can you give me an email to add you to my github repository so I can share with
   you my code?
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/#post-11522792)
 * I try to explain better myself: I got Devin Vinson boilerplate plugin and I customized
   it with my code that you can see above. Now, my code returns this error because
   $wpdb global variable or ABSPATH constant isn’t visible or declared. But how 
   can I include it in my custom code? Excuse me if I can’t be able to explain me.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/#post-11521835)
 * Updating: I tried to require wp-db.php with ABSPATH constant but this results
   undefined. It’s the same result of global variable $wpdb as null: why this?
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/#post-11518403)
 * I’m sorry I answer instantly. It’s a function of a custom class into the boilerplate
   plugin of Devin Vinson. In the activator function the global variable works instead
   into the custom class it doesn’t work.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [PHP Fatal error: Uncaught Error: Call to a member function query() on null](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/php-fatal-error-uncaught-error-call-to-a-member-function-query-on-null/#post-11516070)
 * This is a plugin that I’m developing and I called this global variable also in
   another file of this plugin and it work but in this case it returns null and 
   it doesn’t work so why it doesn’t work?
    -  This reply was modified 6 years, 11 months ago by [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/).
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Problem with HTTP API](https://wordpress.org/support/topic/problem-with-http-api/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/#post-11498295)
 * Ok thanks. I solved with the PHP method file_get_contents().
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Problem with HTTP API](https://wordpress.org/support/topic/problem-with-http-api/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/#post-11498204)
 * Call to undefined function wp_remote_get(). I loaded WordPress: why do I receive
   this error?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Smush – Image Optimization, Compression, Lazy Load, WebP & CDN] Optimize images](https://wordpress.org/support/topic/optimize-images-5/)
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/optimize-images-5/#post-11434125)
 * [@vanyukov](https://wordpress.org/support/users/vanyukov/) I’m using the bulk
   smush with “automatic smush” and “metadata” options active in the settings. Why
   has GTmetrix served me “optimize images” voice yet?

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/users/richdeveloper/replies/page/2/?output_format=md)
[→](https://wordpress.org/support/users/richdeveloper/replies/page/2/?output_format=md)