I've made as script using file_get_html. I'm now transfering it to a Wordpress site, and it doesn't seem to work.
Just trying to use it in a admin plugin.
Snippet below:
require('includes/simple_html_dom.php');
if (isset($_POST['submit_updateColors'])) {
$qGetBrands = $mysqli->query("SELECT ... ");
while ($rowBrands = $qGetBrands->fetch_assoc()) {
$brandId = $rowBrands['cl_brand_Id'];
$url = "https://www.url.com". $rowBrands['cl_brand_url'];
$html = file_get_html($url);
$html->find('div[class=col-md-1p5]');
foreach($html->find('div[class=col-md-1p5]') as $brandColors) {
foreach ($brandColors->find('h3') as $brandColor) {
$p_brandColor = $brandColor->innertext;
}
foreach ($brandColors->find('img') as $ColorImg) {
$p_ColorImg = $ColorImg->src;
}
echo $p_brandColor ." <br />";
echo $imgName['basename'] ." <br /> <br />";
}
}
}
After while have started:
echo "I'm here!!!"
Results: "I'm here!!!"
After first foreach:
echo "I'm here!!!"
Results: Nothing
After $html = file_get_html($url);:
echo "Result: ".$html;
Results: Nothing, not even showing "Result"
Error messages:
Fatal error: Uncaught Error: Call to a member function find() on boolean in /home/xxx/public_html/wp-content/plugins/Farbkarte/index.php:67 Stack trace: #0 /home/xxx/public_html/wp-includes/class-wp-hook.php(286): main_init('') #1 /home/xxx/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 /home/xxx/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/xxx/public_html/wp-admin/admin.php(224): do_action('toplevel_page_f...') #4 {main} thrown in /home/xxx/public_html/wp-content/plugins/Farbkarte/index.php on line 67
I have no idea how to proceed, and would love to get some help! Outside wordpress, it works perfectly.
I hope I havent removed too much informaton.
Thanks in advance!
error_reporting(E_ALL);
andini_set('display_errors', 1);
Start from there.. I suspect that some includes are missing and you have to use the global $db object to access the db in WP. – Eriks Klotins