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?
- Grab the first paragraph of each post
- 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
- Setting hero/splash section as a blog post
- posts_nav_link(); not showing up on static pages
- How to retrieve an image from a post and display it before excerpt of a post? [duplicate]
- Finding Page Template and Displaying Content
- Cannot update WordPress General Settings Site Title and Tagline
- How do I update WooCommerce template files in my theme? [closed]
- How WordPress converts URL to $query_string
- Unhook action from child theme
- Why is the first query affecting the second query, even after wp_reset_query() and wp_reset_postdata(), but not on the second page?
- Link won’t show using the_permalink();
- Some doubts about how to show posts in a custom theme?
- 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
- paged > max_num_pages won’t throw 404
- Displaying recent post excerpts on static front page
- Display a list of certain categories by ID
- Limit Loop to 5 Posts?
- How to override checkbox styles if these inputs have a unique id [closed]
- How to show user online status on their posts?
- Custom Field created in add_meta_boxes reappearing itself again in the default Custom Metabox
- How to add material design css in wordpress and woocommerce
- Storefront child theme not applying parent theme [closed]
- 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?
- page.php dependent sites are not working in custom woocommerce theme
- Zoom on custom theme without child
- How to list articles by year based on url?
- What is the diferences between pure WordPress theme and Woocommerce theme? [closed]
- get_term_link is Ending to single.php
- 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
- Want to add cart and a search bar in the right of logo line
- 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
- How can I sort my loop based on meta data, using a form?
- List categories of a post hierarchically?
- Exclude parent categories from the_category() within the loop
- how to add a badge on product based on filter?
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Woocommerce AJAX filters option loading spiner – problem on mobile device
- Show only pages you are author of
- Add class every 4 post like , class_1, class_2, class_3, class_4 and class_1, class_2, class_3, class_4
- How do I add filter with woocommerce categories?
- WordPress Insert ads after every 5th post
- 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
- Woocommerce REST API for my account & checkout process
- my ajax wont sent the data, please correct my code
- Edit Product Archive design for Woo theme
- How to show Custom Field Value in Woocommerce Shop Page
- how to edit woocommerce checkout page
- How to fix a conflict cause by my theme with Woocommerce and/or Gravity Forms?
- control posts order by select option
- WooCommerce – edit templates
- Problem with Displaying Custom Theme Page’s Content
- Why content is not adding for each blog post
- Display current taxonomy slug in a post