First: don’t use query_posts
. Second: use $wp_query
instead:
$args = array (
'category_name' => 'entertainment',
'posts_per_page'=> 5
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
}
else {
// no posts found
}
Related Posts:
- Get the number of posts from the current page results
- Pagination on category.php and tag.php not working
- Paginate pages with dynamic query
- Function the_posts_pagination() not compatible with WP_Query arguments
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Show number of posts AND number on current page (cannot make it work)
- Pagination only showed when no category is set in wp_query
- Some doubts about how the main query and the custom query works in this custom theme?
- Multiple WP_Query loops with Pagination
- WP_Query vs get_posts
- Pagination returns 404 after page 20
- Order posts by ID in the given order
- Pagination with WP_Query is buggy – working for some pages, but not the others
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- Pagination with 5 posts per page
- How to order category.php loop by ‘meta_value’?
- Pagination/infinite scroll with WP_Query and multiple loops
- Pagination Not working on Home Page with 2 Query
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- Transient pagination not working properly
- Display one latest post from multiple categories
- Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?
- Woocommerce custom loop to show all the products [closed]
- How to bring specific post to front of wordpress loop?
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- Too many posts cause slow load when paginating
- Pagination stops at page 6
- Paginated HTML Sitemap
- Multiple WP_Query loops with Pagination Not Working
- Posts loop with pagination on a single post page
- 2 loops on page – one with orderby rand second orderby date
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pagination is broken and I need help fixing it
- How to show subcategories using loop?
- Storing query variable and then using wp_reset_query
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- WP_Query condition affects posts_per_page count
- How to get all unique categories for posts in loop?
- Blog post per page setting conflicting with custom WP_Query?
- posts_per_page not working for first page of pagination
- Check if loop has any categories?
- Some doubts about how the main query and the custom query works in this custom theme?
- Multiple Loops on category.php with pagination on last loop
- How do I get my custom query to work with search results after the first page?
- How do I rewrite this loop as a new WP_Query style-loop?
- Include current post into loop
- How to provide meta_key array to wp_query?
- get_posts output always same post
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- Get posts that do not have the same tags as current
- wp_query is showing posts from other categories
- Should I reset $wp_query?
- WP_Query with one category in args shows other categories
- Second loop pagination changes URL, not content
- I am officially missing something about transient posts
- Query Not working as expected
- filter posts by meta key with pagination
- Trouble Making WP_Query paged
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- Filter products on category AND tag
- adding pagination to a foreach loop in wordpress
- How do I stop the same post showing multiple times in a archive?
- How to show specify category template for both parent and child category
- Pagination inside the blog page not working
- Problem with my loops
- Custom Query Pagination not working on static front page
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Display 3 levels of categories on page
- Paging works correctly on local version, but not live?
- I have 3 categories, i want to display on a loop the last 3 of every category
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Pull posts from all categories if quantity is not met?
- query_posts() doesn’t seem to be called in my page
- Some doubts about how the main query and the custom query works in this custom theme?
- Retrieving category pages from subcategory returns empty sets
- 2 Loops on one page – pagination of 2nd loop ignore array of excluded posts
- Pagination returns 404 after page 20
- Ordering Posts by parent category, name ascending
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Pagination not working with WP_QUERY
- WordPress Numeric Pagination with Query String [duplicate]
- No content found on page 2 of pagination with 1 post per page
- wp_query pagination links producing 404
- Converting an existing query_posts to WP_Query
- Loop being strainge
- Multiple loop for “featured” items returns wrong posts
- Pagination in custom query not working [duplicate]
- Pagination problem with multiple loops on the same page
- query_posts problem – need help
- WordPress Post Looping? [duplicate]
- Pagination in category.php not functioning