TEXT 12
Untitled Guest on 6th October 2023 05:54:14 PM
  1. <?php
  2. /**
  3.  * Template Name: Bjuuti kampaania Template
  4.  */
  5.  
  6. defined( 'ABSPATH' ) || exit;
  7.  
  8. get_header( );
  9.  
  10.  
  11. $args = array(
  12.     'post_type' => array('product', 'product_variation'),
  13.    // 'posts_per_page' => -1, // Set to -1 to retrieve all products.
  14.    'posts_per_page' => 12,
  15.     'paged' => $paged,
  16.     'meta_query' => array(
  17.         array(
  18.             'key' => 'bjuuti', // Replace with your custom field name.
  19.             'value' => '1', // Only show products with this value.
  20.             'compare' => '=',
  21.         ),
  22.     ),
  23. );
  24.  
  25. $custom_query = new WP_Query($args);
  26.  
  27.         if ( $custom_query->have_posts() ) :
  28.                 while ($custom_query->have_posts()) {
  29.                         $custom_query->the_post();
  30.                         wc_get_template_part('content', 'product-cat'); // This loads the product content template.
  31.                 }      
  32.                        
  33.  
  34.                 // Pagination.
  35.                 echo '<div class="pagination">';
  36.                 echo paginate_links(array(
  37.                         'total' => $custom_query->max_num_pages,
  38.                         'current' => max(1, get_query_var('paged')),
  39.                 ));
  40.                 echo '</div>';
  41.         else :
  42.                 echo 'No products found.';
  43.         endif;
  44.  
  45.        
  46. wp_reset_postdata(); // Reset the post data to avoid conflicts.
  47.  
  48.  
  49. get_footer( );

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.