I think you could use the posts_per_page
argument in your get_posts
query:
$args = array( 'child_of' => 1 );
$categories = get_categories( $args );
foreach ($categories as $category) {
echo '<li><a>'.$category->name.'</a>';
echo '<ul>';
$posts_args = array(
'posts_per_page' => 9,
'category' => $category->term_id
);
foreach (get_posts($posts_args) as $post) {
setup_postdata( $post );
echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';
}
echo '</ul></li>';
}
Related Posts:
- Very slow query
- How to get category link without a database query
- WP_query category__in not working, only pulls from first category
- Does meta_query work within get_posts array?
- How to optimize my query filtering out unwanted data?
- Remove posts from query for events whose start date has passed
- get_posts() loop returns the same the_title() for each post
- List all posts from past week grouped by sub-category
- Order posts by custom field DATE value
- How do I see the mysql query generated by get_posts( $args )?
- Create Indexes for Slow Queries
- Multiple Category Query
- list all categories that have a certain word in title
- get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)
- pre saved posts query from db options table
- Re-sort get_posts query results
- Can I include get_posts in this array?
- How can I get posts by 2 meta keys, prioritising one of them?
- Category_in return empty
- Sort order in get_posts [closed]
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- Is there a way of increasing the speed of this query?
- How can I query all users who registered today?
- Reversing the order of posts AFTER the query is performed
- what are the numbers between curly brackets in search query
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Search custom post type by meta data
- Multipart/formatted MySQL query problem
- Remove [gallery] shortcode altogether
- query multiple taxonomy and show post count
- Categories and products in random order
- add_query_arg() XSS Vulnerability
- Custom Query to search through categories
- is there a better way of combining this?
- Show post only if match all categories
- How Do I Merge Categories With phpMyAdmin
- How to mass delete one line from all posts after site hack
- Query posts by content lenght
- $wpdb doesn’t appear to work on page inside of a plugin
- Show recent posts from one category on a non-WP site
- Search query -> Show all pages except certain template
- Get attachments for posts that belongs to a specific category
- Show popular post by category code
- How can I setup a relationship using categories in WordPress?
- WordPress Query wp-terms SLOW
- I can’t figure out what’s wrong with this statement. $wpdb->query update
- Problem when try to add ++1 for user meta
- query statement containing variable won’t execute
- Get posts from category with custom query
- Related post based on content
- Slow Search Queries – How to exclude pages, media, excerpt, authors, private posts?
- WP_User_Query with more than two custom meta values
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- how do i register global query in template
- Get categories of queried posts
- Combining two meta_values within one row with query
- Conditional category query breaking?
- Category name for all posts getting assigned to a single random post
- Sort query_terms_list for post_tags alphabetically
- Target a page with query
- List only parent attributes on woocommerce admin atrributes page
- Merge CPT Taxonomy and Post Taxonomy in $query->set
- How do I get specific readable results from this query and array results
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Add rewrite rule for archive search
- How to create a filter and add query params to all links
- Get 2 meta values from meta key column
- WordPress add_query_arg from ajax and make url friendly
- My custom pagination not displaying
- Adding Category in WP_Query Not Working
- How to Get Position of a Post from a category and tag
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Query posts from newest category
- Query reversed when I use “category__not_in”
- How to reduce the load / no of queries on MySql Database
- $query->set( ‘post_type’, ‘post’ ); not working
- How i make a custom sql query for Woocommerce
- Display result from custom post meta query
- Show certain number of post from tags
- Wpdb empty result only if language is Russian
- Include custom table in query
- How to fix this insert? Don’t work for me!
- Display Upload Author & Get Uploaded Post ID
- Display list of most recent grandchild (third tier) pages
- How can I display a number to represent the order of post?
- Update vs Insert logic but the last key is always inserted?
- Query unique author ids with published post of type job
- Wpdb generates too many queries
- Custom Query for searching through custom fields
- Query posts alphabetically within this function
- Conditional Tag Custom Querys?
- get posts from 2 categories. (2 posts)
- query posts only works on the first page
- Custom Query for wp_posts using wp_postmeta
- WP Query outputs three items within a div
- Query filter on custom post by current author in post widget for elementor query id
- Sort Posts Alphabetically Based on Specific Category (Divi)
- Querying Posts from ACF Repeater Subfield Select Value