unid_user 63 ارسال شده در آذر 00 گزارش بازنشر ارسال شده در آذر 00 سلام و درود دوستان گرامی برای نمایش آخرین محصولات یکی از دسته بندی های ووکامرس بر اساس slug یه کوئری نوشتم که در بخش آرگومان ها به مشکل خوردم. <?php $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => 12, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', //This is optional, as it defaults to 'term_id' 'terms' => '$carousel_item["cat_id"]', //اینجا مشکل دارم 'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'. ), ) ); مقدار terms و به هرشکلی که وارد می کنم محصولات اون دسته بندی و نمایش نمیده. البته نمیخوام مستقیم به terms مقدار بدم و میخوام این و از آرایه ای که در یک حلقه foreach نوشتم بخونه. کل کدها و حلقه ای که نوشتم و به صورت زیر هست. لطفا راهنمایی کنید برای حل این مشکل چه کار کنم. سپاس <?php $home_crousel_cats = testcodes_get_option('home_crousel_cat'); ?> <?php $i=0; foreach($home_crousel_cats as $carousel_item) { ?> <section class="my-3 home-latest-category-items"> <div class="container"> <div class="row"> <div class="col-12"> <h2 class="text-center bg-white home-latest-category-items-title"> <a href="<?php echo $carousel_item['cat_url']; ?>" class="text-dark"> <?php echo $carousel_item['cat_title']; ?> </a> </h2> <span class="d-block home-title-under-line"></span> </div> </div> <div class="row"> <div class="col-12"> <div class="mt-3 owl-carousel owl-theme"> <?php $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => 12, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', //This is optional, as it defaults to 'term_id' 'terms' => '$carousel_item["cat_id"]', 'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'. ), ) ); $post_cat = new WP_Query( $args ); if ( $post_cat->have_posts() ) { ?> <?php while ( $post_cat->have_posts() ) : $post_cat->the_post(); ?> <div class="item"> <a href="<?php the_permalink(); ?>"> <?php woocommerce_template_loop_product_thumbnail(); ?> </a> <h3 class="mt-2 text-center home-product-title"> <a href="<?php the_permalink(); ?>" class="text-secondary"> <?php echo wp_trim_words( get_the_title(), 10 ); ?> </a> </h3> <span class="text-center d-block home-product-price"> <?php echo $product->get_price_html(); ?> </span> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> <?php } else { echo "<div>با عرض پوزش محصولی جهت نمایش یافت نشد.</div>"; } ?> </div> </div> </div> </div> </section> <?php $i++; } ?> نقل قول لینک به ارسال
unid_user 63 ارسال شده در آذر 00 مالک گزارش بازنشر ارسال شده در آذر 00 در 16 دقیقه قبل، unid_user گفته است : سلام و درود دوستان گرامی برای نمایش آخرین محصولات یکی از دسته بندی های ووکامرس بر اساس slug یه کوئری نوشتم که در بخش آرگومان ها به مشکل خوردم. <?php $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => 12, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', //This is optional, as it defaults to 'term_id' 'terms' => '$carousel_item["cat_id"]', //اینجا مشکل دارم 'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'. ), ) ); مقدار terms و به هرشکلی که وارد می کنم محصولات اون دسته بندی و نمایش نمیده. البته نمیخوام مستقیم به terms مقدار بدم و میخوام این و از آرایه ای که در یک حلقه foreach نوشتم بخونه. کل کدها و حلقه ای که نوشتم و به صورت زیر هست. لطفا راهنمایی کنید برای حل این مشکل چه کار کنم. سپاس <?php $home_crousel_cats = testcodes_get_option('home_crousel_cat'); ?> <?php $i=0; foreach($home_crousel_cats as $carousel_item) { ?> <section class="my-3 home-latest-category-items"> <div class="container"> <div class="row"> <div class="col-12"> <h2 class="text-center bg-white home-latest-category-items-title"> <a href="<?php echo $carousel_item['cat_url']; ?>" class="text-dark"> <?php echo $carousel_item['cat_title']; ?> </a> </h2> <span class="d-block home-title-under-line"></span> </div> </div> <div class="row"> <div class="col-12"> <div class="mt-3 owl-carousel owl-theme"> <?php $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => 12, 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'slug', //This is optional, as it defaults to 'term_id' 'terms' => '$carousel_item["cat_id"]', 'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'. ), ) ); $post_cat = new WP_Query( $args ); if ( $post_cat->have_posts() ) { ?> <?php while ( $post_cat->have_posts() ) : $post_cat->the_post(); ?> <div class="item"> <a href="<?php the_permalink(); ?>"> <?php woocommerce_template_loop_product_thumbnail(); ?> </a> <h3 class="mt-2 text-center home-product-title"> <a href="<?php the_permalink(); ?>" class="text-secondary"> <?php echo wp_trim_words( get_the_title(), 10 ); ?> </a> </h3> <span class="text-center d-block home-product-price"> <?php echo $product->get_price_html(); ?> </span> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> <?php } else { echo "<div>با عرض پوزش محصولی جهت نمایش یافت نشد.</div>"; } ?> </div> </div> </div> </div> </section> <?php $i++; } ?> درست کردم. فقط باید مقدار terms و بصورت زیر بنویسم. <?php 'terms' => $carousel_item['cat_id'], نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .