Я занимаюсь разработкой WordPress сайта (электронная торговля), мы используем темы Woocommerce и Sage 9. После обновления php до 7.4 эта проблема возникла.
Исключение Uncaught: вызов функции-члена have_posts () для null (Просмотр: ... views / template-home.blade. php)
This мой код от: template-home.blade. php
@php
woocommerce_product_loop_start();
@endphp
@while($get_products->have_posts())
@php
$get_products->the_post();
//global $product;
//$product = wc_get_product(get_the_ID());
//echo Casey_Pro_Helper::getvar($product);
//do_action('woocommerce_shop_loop');
wc_get_template_part('content', 'product');
@endphp
@endwhile
@php
wp_reset_query();
woocommerce_product_loop_end();
//woocommerce_pagination();
do_action('woocommerce_after_shop_loop');
$total = $get_products->max_num_pages;
$request_uri = $_SERVER['REQUEST_URI'];
preg_match_all('/\//', $request_uri, $matches, PREG_OFFSET_CAPTURE);
$current_page = 1;
if (!empty($matches) && array_key_exists(1, $matches[0]) && array_key_exists(2, $matches[0])) {
$first_slash_position = $matches[0][1][1];
$last_slash_position = $matches[0][2][1];
$length = strlen($request_uri) - $last_slash_position;
$current_page = (int)substr($request_uri, $first_slash_position + 1, $length);
}
$base = isset( $base ) ? $base : esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
$format = isset( $format ) ? $format : '';
@endphp
<nav class="woocommerce-pagination">
@php
echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
'base' => $base,
'format' => $format,
'add_args' => false,
'current' => max( 1, $current_page ),
'total' => $total,
'prev_text' => '←',
'next_text' => '→',
'type' => 'list',
'end_size' => 3,
'mid_size' => 3,
) ) );
@endphp
</nav>
</div>
</div>
</div>
Это контроллер: TemplateHome. php
<?php
namespace App\Controllers;
use Sober\Controller\Controller;
class TemplateHome extends Controller {
/**
* Return news
*
* @return array
*/
public function GetProducts() {
$include_ids = \App\run_equal_names_query();
$request_uri = $_SERVER['REQUEST_URI'];
preg_match_all('/\//', $request_uri, $matches, PREG_OFFSET_CAPTURE);
$page = 1;
if (!empty($matches) && array_key_exists(1, $matches[0]) && array_key_exists(2, $matches[0])) {
$first_slash_position = $matches[0][1][1];
$last_slash_position = $matches[0][2][1];
$length = strlen($request_uri) - $last_slash_position;
$page = (int)substr($request_uri, $first_slash_position + 1, $length);
}
$paged = $page;
$posts_per_page = 9;
$offset = (($paged-1)*$posts_per_page);
$args = [
'ep_integrate' => false,
'post_type' => 'product',
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'offset' => $offset,
'post__in' => $include_ids,
'meta_query' => [
[
'key' => '_stock',
'value' => 0,
'compare' => '>'
]
],
'orderby' => 'modified',
'order' => 'DESC'
];
$home_products_query = new \WP_Query($args);
return $home_products_query;
}
Как это исправить