pre_get_posts with get_posts

Firstly, you are invoking an infinite loop, which causes the memory exhaustion. To avoid it, put the following at the beginning of your function: // avoid infinite loop remove_action( ‘pre_get_posts’, __FUNCTION__ ); It makes sure the you are not hooking it into pre_get_posts over and over again, re-initiating your get_posts() call over and over again. … Read more

WP_Query for WooCommerce Products

<ul class=”products”> <?php $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 12 ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); wc_get_template_part( ‘content’, ‘product’ ); endwhile; } else { echo __( ‘No products found’ ); } wp_reset_postdata(); ?> </ul><!–/.products–>

Show all products on one page with WooCommerce

Just add the conditional check to your functions.php file: if( isset( $_GET[‘showall’] ) ){ add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return -1;’ ) ); } else { add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 12;’ ) ); }

Archive Listings Filtered by Date Values in a Custom Field/Post Meta?

As with many things in WordPress there are several ways to do what you want. I’m going to explain one of them. Remove the ‘year’, ‘monthnum’ and ‘day’ Query Variables You can modify the parameters to the query WordPress uses on the archive URLs inside the ‘pre_get_posts’ hook. Those parameters are captured as an associative … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)