php loop error for count posts in category

I have a working solution now… finally! <?php foreach ( $categories as $category ) { // If there is only one post available, go directly to the post if($category->count == 1) { $all_posts = get_posts($category); echo ‘<div class=”item”><h4 class=”item-title”>’ . get_the_title($all_posts[0]->ID) . ‘</h4><a href=”‘ . get_permalink($all_posts[0]->ID) . ‘”>Read more</a></div>’; } else { echo ‘<div class=”item”><h4 … Read more

Pagination Not Working When Used With WP_Query() `offset` Property

WP_Query docs gives a warning about the offset parameter: Setting the offset parameter overrides/ignores the paged parameter and breaks pagination. Try something like this: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $newsArticles = new WP_Query(array( ‘posts_per_page’ => 16, ‘post_type’=> ‘news’, ‘paged’ => $paged, )); while( $newsArticles->have_posts()){ $newsArticles->the_post(); ?> // HTML <?php } ?> $big = … Read more

How do I make my terms for each product display via foreach loop? (woocommerce)

The problem is here: while ( $query->have_posts() ) { $query->the_post(); function filter_categories($categories) { foreach ($categories as $category) { echo $category->name; } } You shouldn’t declare a function inside a loop. Every time it loops around the filter_categories function gets declared again, but named functions can only be declared once, so it crashes the second time … Read more