0

I have a strange problem. In PHP 7.4 my script for generating XML for other comparison site worked well, but after upgrading PHP to 8.0 it doesn't work anymore.

In sandbox I got these errors:

Fatal error: Uncaught Error: Class "WP_Query" not found in /home/user/scripts/code.php:78
Stack trace:
#0 {main}
thrown in /home/user/scripts/code.php on line 78

and the code in line 78 looks like this (last line with WP_query):

// FETCH ALL PRODUCTS
$args = array(
    'posts_per_page' => -1,
    'post_type' => 'product'
);

if( count( $config['exclude-products'] ) ) {
    $args['post__not_in'] = $config['exclude-products'];
}

// PRODUCT LIMIT (1 product can have multiple variations)
if( isset( $_GET['limit'] ) && $_GET['limit'] ) {
    $args['posts_per_page'] = $_GET['limit'];
}

if( isset( $_GET['offset'] ) && $_GET['offset'] ) {
    $args['offset'] = $_GET['offset'];
}

$products = new WP_Query( $args );

Can somebody help me what to do as I am not a programmer.

2
  • 2
    This isn't likely to be PHP 8 I don't think. Unless it's somehow breaking a require, but you'd get an error for that. Do you get any warnings or errors? How are you calling this file? I assume you're trying to load it directly, and not through WordPress itself?
    – Rup
    Commented Dec 20, 2022 at 14:28
  • 4
    Wait, /home/user/scripts/code.php doesn't look like a WP path, it should either include_/themes/_ or /plugins/. How is this file actually loaded?
    – kero
    Commented Dec 20, 2022 at 15:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.