我创建了一个在页面中传递 ID 的 ajax 文件。并且该页面有一个查询。我有一个错误。我试图知道我的错误是什么,有些网站说我必须定义我的模板并需要 wp-load.php,但有些网站说我必须在 function.php 上做。我真的不知道该怎么办。我是 wordpress woocommerce 的新手。
未捕获的错误:在 xxxx/xxxx 中找不到类“WP_Query”
这是我的页面 (get-fabric.php)
<?php
if(!empty($_POST['select_colour']))
{
$args = array(
'post_type' => 'product',
'posts_per_page' => 1000,
'product_cat' => 'fabric'
);
$query = new WP_Query($args);
while ( $query->have_posts() ) : $query->the_post();
global $product;
$regular_price = $product->get_price_html();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $query->post->ID ), 'product' );
echo ' <div class="col-md-3 fabric-active" data-fabcode="32860">
<div class="fabric-cloth">
<div class="fabric-data">
<img src="'.$image[0].'" class="img-responsive cursor-on" />
<div class="fabric-code">
<p>'.$product->post->post_title.'</p>
<span>'.$regular_price.'</span>
</div>
</div>
</div>
</div>';
endwhile;
wp_reset_query(); …Run Code Online (Sandbox Code Playgroud)