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 round, and everything stops.
If you look in your PHP error log, you should see an error message about redeclaring filter_categories
confirming this.
Related Posts:
- get_the_terms() returning wrong results inside of loop
- Get ‘page’ number with infinite scroll
- Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere
- Why doesn’t /2013/01/ properly return January’s archives in archive.php?
- Strategy to get post meta for use outside the loop
- Where do I find the functions triggered within a hook?
- Single Page WordPress Theme – Using page templates
- A two column loop with one lead post
- Change loop order via form or link (jquery, not URL)
- First post of each category
- Is there any need to use both wp_reset_postdata and wp_reset_query together?
- query posts in wordpress
- Getting Permalink within the loop
- the_content() in single-{post-type}.php problem
- Why does this loop only work on the homepage?
- Demo Import changes terms ids
- Writing Clean WooCommerce Styles
- Finding Page Template and Displaying Content
- How do I update WooCommerce template files in my theme? [closed]
- How WordPress converts URL to $query_string
- Unhook action from child theme
- Link won’t show using the_permalink();
- Force index.php have_posts() loop to exit if no sticky posts found
- A mystery 300px image size
- How to call WooCommerce update cart function programatically
- show a post from a specific post format
- Displaying recent post excerpts on static front page
- Display a list of certain categories by ID
- How to override checkbox styles if these inputs have a unique id [closed]
- How to show user online status on their posts?
- Custom get_the_excerpt() only works on first post
- StoreFront product pages: Turn the Short Description section into a kindred tab section [closed]
- How can I fetch the WordPress cart errors normally displayed in woocommerce-error?
- Scroll to position on page for category pages only — woocommerce
- Echo all category names, apart from one
- Can’t remove DIV from hooks in Storefront child theme [closed]
- how to get the post attachement image in full size?
- Get the amount of posts on a given page
- How to list articles by year based on url?
- What is the diferences between pure WordPress theme and Woocommerce theme? [closed]
- Change image size depending on page
- How can I prevent posts with no title showing up in my query?
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- why mytheme/single-product.php works but not mytheme/woocommerce/single-product.php
- Previous and Next links not populating, have I missed something?
- Why does admin-ajax load slow and what are ways to speed it up?
- Adding an external link to product grid list pages for woocommerce
- Issue when posting updates/changes to wordress
- Twenty Seventeen Pages Loop
- How does the loop know which post to view?
- Woocommerce Product attribute not imported with wordpress Importer [closed]
- Add a field to the taxonomy editor?
- Retrieve WordPress’ the_content() with jQuery
- Exclude subcategory from wp_query
- Style first 3 posts differently with WP_Query [duplicate]
- WP_Query not getting all posts, just tagged posts
- first excerpt fine, subsequent post excerpts shift to the right instead of displaying vertically [closed]
- Pagination and multiple loops
- List categories of a post hierarchically?
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Woocommerce AJAX filters option loading spiner – problem on mobile device
- Add class every 4 post like , class_1, class_2, class_3, class_4 and class_1, class_2, class_3, class_4
- White screen of death on index.php page 3 and above?
- Best way to declare product variables in woocommerce theme development?
- WordPress theme files Organization
- Alter shop page lay-out in OceanWP theme
- Infinite loop when nesting have_posts()
- Local variable name in setup_postdata()
- Get categories within specific term
- Is it possible to echo a woocommerce prouct attribute discription?
- Loop is breaking my theme. How can I fix?
- the_content() not displaying description correctly
- my ajax wont sent the data, please correct my code
- Edit Product Archive design for Woo theme
- how to edit woocommerce checkout page
- WooCommerce – edit templates
- Problem with Displaying Custom Theme Page’s Content
- Display current taxonomy slug in a post
- Woocommerce Theme Reviews / Comments
- Conditional loop based on current page
- Suppress the_content filter in a nested loop
- Tags interfering with next_post_link();
- Simple loop with shortcode rendering problem
- How get the 10 most viewed pages (not post)
- The normal loop with different styles doesn’t work in search.php
- Checking conditionals
- issue displaying variations in custom template using WPeC 3.8.9.2
- All post ids are the same after this query but rewind_posts() does not seem to work here?
- Not Found when using activity stream as front page with BuddyPress
- php file child theme directory not overriding parent theme php file [duplicate]
- Pagination adds product to cart Woo-Commerce
- have_posts() return false on single post
- How to defeat “Blog pages show at most __ posts” setting in the loop?
- Display Page featured Image as well as Posts featured Image
- How to change order of elements using a child theme
- How to install Woocommerce without plugin?
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- WordPress Two Level Filters on Getting Custom Taxonomy Terms
- Add text when displying attribute with a hook on single product page