I found a problem. I had to change this:
$args = array(
'cat' => $category->name,
'posts_per_page' => 3,);
for this:
$args = array(
'category_name' => $category->name,
'posts_per_page' => 3,);
In first code I was passing category name which is string to argument expecting ID of category. Here is Codex reference where I found solution:
- category_name (string) – use category slug.
- category__and (array) – use category id.
- category__in (array) – use category id.
- category__not_in (array) – use category id.
Related Posts:
- Why should i use wp_reset_postdata()?
- When should you use wp_reset_postdata vs wp_reset_query?
- Reset postdata to custom query in nested queries
- Why am I getting no results of a query placed after another query?
- Exclude or Include category ids in WP_Query
- WP_Query to show post from a category OR custom field
- Display recent posts from the same category as current post in sidebar
- How to filter by category in REST API, excluding posts also in other category term?
- Counting number of posts with Category B in Category A
- How to order category.php loop by ‘meta_value’?
- Use Transient API to cache queries for all posts in all categories?
- How can I display recent posts from a particular category in my header?
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- How get posts from a subcategory of a category by name?
- Get image of latest post from taxonomies/categories
- How To Remove/hide some specific categories from two different categories widget from sidebar
- WP_Query arguments to fetch custom post type posts which are in certain category?
- How do I reset this wp_list_categories query?
- How to show subcategories using loop?
- List of the years with posts presented
- Remove a specific category ID from related post
- Complex Category selection as per user input
- Show all post for a given category
- Five posts from a category in footer
- How to get all unique categories for posts in loop?
- Display Featured Post by Categories and Avoid duplicated posts
- Cluster WooCommerce products in each Category Archive by Tags assigned to products
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- Can we return all category (not post) with Custom Query Filter? [closed]
- Query posts intersecting tags and categories
- Query posts from category A, and from either category B or C
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- reset to main loop doesnt work
- Combining categories (Query posts with multiple taxonomy terms)
- Check if loop has any categories?
- Filtering out child category posts from parent category archive not working
- wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query
- Exclude Category filter from Portfolio section
- WP CLI can’t delete plugin related table
- Inserting HTML to close and open divs in WP_Query loops
- Limiting number of related posts
- Category ‘pad_counts’ & ‘parent’ conflict
- Include posts from some categories while excluding from others
- Combine results of multiple WP_Query to resemble single WP_Query
- Set post number to single posts
- WP_Query and is_page_template() conditional
- WordPress Custom Search Form Displaying Unexpected Results
- Hide products in uncategorized category from search results
- How to echo woocommerce category name
- Slider won’t work with custom query
- WP_Query with one category in args shows other categories
- Loop categories by recent post
- How order posts from category by date and comment count?
- How to get posts by category and by choosing a taxonomy term?
- Getting the permalink to the latest post from a category
- What is wrong with my WP_Query Arguments?
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- get_the_terms has strange result since version 6.0
- Filter sub-category from checkbox form
- `offset` WP_Query argument dont work via `pre_get_posts`
- Use get_cat_ID to retreive multiple category IDs
- Function the_posts_pagination() not compatible with WP_Query arguments
- Filter products on category AND tag
- adding pagination to a foreach loop in wordpress
- How to display the category dropdown auto search list when key press?
- Get categories within specific term
- Related categories order posts by category
- How to show specify category template for both parent and child category
- Exclude parent categories from recent posts list
- Display All Top Child Categories / Taxonomy
- Unable to reset post data in wordpress custom query
- Check the product in the cart from which category is and show message
- WP_Query showing all posts, except from category X, unless it’s also in Y
- Single query for multiple categories
- Show posts from categories instead of tags
- Multiple values in WP_Query : category__and
- How to exclude posts by ID within a category/archive loop
- I have 3 categories, i want to display on a loop the last 3 of every category
- Adding Category in WP_Query Not Working
- display all posts from category with and without terms in chronological order
- Pull posts from all categories if quantity is not met?
- Calling a function with WP_Query only ever brings the first result
- Category Archive not working for pages
- Retrieving category pages from subcategory returns empty sets
- query.php – multiple is_category functions
- Correct Way To Run Multiple Queries Sharing Some Base Data
- Display Count of posts
- Display post list within category list sorted by name [duplicate]
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Different number of posts showing in development vs production server
- Loop being strainge
- query_posts problem – need help
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Filter posts by category
- Is it possible to make is_category() recursive?
- List categories using WP_Query
- I need to get all categories from a WP_Query
- Advanced Search – Is this possible?
- Pagination only showed when no category is set in wp_query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2