a possible conflict with the name $posts which is used by wp core;
try, for instance:
$categories = get_categories();
foreach($categories as $category)
{
printf('<h2>%s</h2><ul>', $category->cat_name);
$cat_posts = new WP_Query('cat=".$category->cat_ID);
while($cat_posts->have_posts())
{
$cat_posts->the_post();
echo "<li>', the_title(), '</li>';
}
print '</ul>';
}
Related Posts:
- How do I use WP_query with multiple post IDs?
- Query multiple custom post types in single loop
- Inject post (from specific category) between posts in Loop
- Build a content and excerpt grid loop with paging and options for # of posts
- Passing JSON data from WP Query into AJAX causing NULL errors
- Using Cookie Data For WP_Query Loop
- wp_delete_post deletes all posts instead of just expired ones
- Alter secondary loop to exclude posts from current page category
- How to add 2 posts under another post? Formatting should be intact
- Trim first 2 words of the exceprt
- Count number of published posts by type
- How to display custom field on homepage
- Display Post co-authored in Author Page
- Get taxonomy terms only of the WP_Query current posts
- Get the last month with posts using a recursive function…
- Use WP_Query in shortcode
- Why is variable not working on custom sql query using wpdb?
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- How to query for pages/post depending on slug?
- WordPress custom slug (endpoint) and compare all links
- get current custom post ID by WP_Query method
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Create WP_Query to search for posts by their categories or their parent/child categories
- wp_query with cat not working
- If Query In Sidebar
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Compare post-IDs within WP_Query? (Less than / Greater than)
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Display a specific category of products in shop page and disable code for specific actions
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Custom query, checking values of multiple meta keys
- Security for data obtained from the database
- How to get all author posts outside of author templates
- How to get post ID in a Page?
- How to retrieve the data from the sever and displaying it in a page?
- How to overwrite orderby with add_query_var
- get_the_ID() in the footer returns wrong value
- How to override url params with rewrite rules vars?
- How to display SQL query that ran in WC_Order_Query?
- Store metakey value as an array
- Post not populating for custom post type based on category selection
- WP_Query multiple post results
- Infinite Loop – WP_Query
- echo var into wp_query
- Toolbar Hidden in a Virtual Page
- WordPress SQL JOIN query
- WP_Query and help with the loop for magazine front page
- Wp Query : Order by distance lat,lon
- How to WP_Query posts order by parent title?
- search.php to search only the post title
- Let current user know pending posts counts using wp_query
- WP_Query – How to query all of post types categories
- get_terms with specific id order
- How to work Woocommerce pagination inside shortcode?
- get different meta-data of a complicated query at the same time
- Using a new WP_Query inside the loop
- wp_Query with mutuplea values returns all posts
- WordPress sorting posts by date and title using a dropdown
- How to get specific multiple pages excerpts at homepage?
- Use WPQuery to match to specific repeater row in post
- Query on a repeater date (acf)
- WP_QUERY post_in problem
- how to get data from two different table from wordpress database
- Assign meta_query value to php variable
- Trying to get pagination working on WP_Query() post grid
- Check the database for a postmeta field
- WordPress search query, how to modify the sql
- Modify post image in full size
- Wp-query output correct, but the loop shows one less item (only sometimes)
- How to display sticky post always at the top (before regular post) in wordpress?
- Combine multiple queries, array_unique returns nothing
- Making list of posts with chosen description
- Ordering / grouping posts by datepicker ACF
- Include search tags and users in my search results system
- Add custom taxonomy to custom search for posts
- My query keeps looping infinitely ! how to stop it?
- Transfer WordPress Login Session to an Extended Webpage on the Same Domain
- How to add thumbnails from recent posts to owl-carousel in wordpress automatically?
- direct query to post_meta table
- Only Get A Certain Number of Posts From WP_Query
- Querying posts based off a jquery datepicker
- Use custom get results query to show posts WordPress
- List sibling pages widget, exclude current page
- WP Query conflict on tag.php and category.php template
- Does wp_query and query_posts affect website performance? [duplicate]
- WordPress post pagination on custom template not working
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- WP query with variables gives no result for specific user
- Display all categories (with link) of custom post type – WordPress
- Variable ++ in query loop
- XML WP_Query problem in PHP 8.0 and 8.1
- a problem in class in class-wp-hook.php
- Count custom posts type and filter by tag
- AJAX WP_Query’s order and orderby parameters not working
- Add adjacent post function inside custom recent post function
- How do I exclude the current post from the upcoming post query
- How do I display WooCommerce products in my query to rows of 3?
- Exclude first post from wp query
- AND and OR in my CPT search query depending on checkbox