This should work (if your post_type is not post you will need to amend the code)
<?php
$args = array(
'post_type' => 'post',
'cat' => '31',
'posts_per_page' => 5,
);
$query = new WP_Query( $args );?>
<?php if( $query->have_posts() ) : ?>
<?php while( $query->have_posts() ) : $query->the_post(); ?>
<li><a href="https://wordpress.stackexchange.com/questions/209558/<?php the_permalink(); ?>"><i class="fa fa-book"></i> <?php the_title(); ?></a> <span>Di <?php the_author(); ?>, <?php the_time('d/m/Y'); ?></span></li>
<?php
endwhile;
endif;
// Reset Query
wp_reset_query();
?>
Related Posts:
- Get the children of the parent category
- How to check if I’m on the last page of posts?
- Should category.php and The Loop be used if the query needs to be customizable?
- Exclude the category from the WordPress loop
- How do I get the category URL from get_the_category?
- get_field not displaying my custom field value
- Default WP Gallery – show only galleries of a certain category
- Rearranging posts based on categories
- WP_Query not looking at child category
- Randomise results from a category page?
- Display all posts in category, with specific tag posts at top
- Show div only if post is in specific category
- How to create a widgetized sidebar for every category dynamically?
- How to show a category post to a specific registered user
- Display list of Sub-Categories and the posts they contain, within one main Category
- Loop with Dynamic Categories
- How can I create a loop to build slides based on multiple categories using Coda Slider
- Remove child products from woocommerce category page [closed]
- Get a list of commas separated categories inside a loop
- Categories list loop – add separator every year
- How would you create a “weekly” archive?
- Display all posts with same title
- How to exclude categories from recent posts, recent comments & category widgets?
- Listing all posts from current category on page
- Categories and Tags returning 404 on the sidebar when using ugly permalinks
- Display one latest post from multiple categories
- How do I get the total number of categories in a list of search results?
- Check if post belongs to any category
- How do I display the posts from a custom post type on a category.php page?
- How to group the loop posts in a particular by author?
- Exclude posts without category from loop
- Category name for all posts getting assigned to a single random post
- Category post count is not correct
- Display all categories but only if they have posts in them that have a specific tag assigned
- Excluding current category from sidebar’s post widget, elementor, query-id
- Include last post date in get_categories loop
- Show the number of the post
- Custom sidebar isn’t showing up on sub-category posts
- How can I order all subcategories alphabetical independent of the parent categories?
- How to get specific (grand parent) category of current post?
- How do I get conditional sidebars for specific category archives and posts
- Custom Loop with certain number of one category
- how tho change number of posts in loop from specific categories
- Template category.php with page (no posts)
- How to edit woocommerce sub-category page
- error in specific category loop
- loop in single.php of the same category
- How to create a category loop on my blog (ACF Plugin)
- Please tell how to stop the category from showing up on posts
- Hide a category/posts from the homepage in wp
- Sidebar by Category Conditional Statement not functioning
- Loop by category and meta_key
- Print categories and most viewed articles
- Assign a class to first element in category in loop
- Displaying Category in sidebar post widget but not in the loop on home
- Querying posts from two different categories while looping inside another loop
- Trying to display all posts in a category
- Category page shows only 1 post when that post has more than 1 category?
- Configure query with multiple categories in a custom order?
- Display Taxonomies in loop with template args
- How to loop through a custom field for each post, & display?
- show category name before first posts in each category
- How can I modify this code to iterate over an array of categories?
- Loop within category’s posts
- How to exclude a specific categogy from a custom page template
- Display one post on category.php: Wrong featured image
- Loop through posts of CatA and store value of CatB in separate array
- How to add an empty entry to masonry?
- Automatic menu creation for pages with categories?
- WordPress Numeric Pagination with Query String [duplicate]
- Loops in category description
- How to get multiple loop in category.php, my scripts becomes madness
- Several loop in search result
- Printing direct descendants of a category with WP_Query
- Category slug in in loop always the same?
- Custom Category Page Not Working [duplicate]
- how to get number of posts in a category on a specific date
- Sidebar Categories change arrow when subcategories are shown on click
- Show posted on date only for posts in a certain category
- 2 loops in archive.php (one for each category)
- Archives and category of authors
- My Query is getting the wrong data
- Detecting top parent category fails on home page
- How to add the sidebar in all category page
- How do i add custom post types to this query?
- Using pagination with multiple loops causes it to break
- Custom loop by url
- Custom WordPress category page showing all posts rather than the specified category
- How do I hide posts in a category from all listings but still allow the posts to be viewed?
- How to create a custom loop ordered by Categories on a Page Template?
- Do not show all post from all categories, just show posts from category in current loop
- IF have_posts contains posts from a certain category
- Categories not shown on sidebar
- Echo Category In Loop
- How can I implement pagination on custom category page?
- Order Categories by Character Count
- Get categories by title descendant
- Display different sidebar based on search results from one category
- Elementor : display only one category in loop grid
- Different number of posts in regular loop and CPT category page