Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display all posts in WordPress?

Tags:

wordpress

I want to display all post in my WordPress home page.

I have written following query for getting all post but I do not get all posts. It just displays 10 or 11 posts:

 $args = array(
                'post_type' => 'post',
                'posts_per_page' => $number,
                'order' => $sort_by,
                'orderby' => 'title',
                'post_status' => 'publish',
                'tag' => $tags,
                'ignore_sticky_posts' => 1,
                );
 $args['tax_query'] =  array(
                    array(
                    'taxonomy' => 'post_format',
                    'field' => 'slug',
                    'terms' => 'post-format-video',
                    ));
 $query = new WP_Query($args);

So please let me know how can I get all posts.

like image 319
Alpesh-Prajapati Avatar asked Aug 19 '16 21:08

Alpesh-Prajapati


People also ask

How do I show all posts in WordPress?

List All WordPress Posts on Your Homepage. If you'd like all your posts displayed on your front page along with the content of the posts, you can easily do that by going to the Reading Settings screen (Settings > Reading) and changing the number of posts to show to something more than the number of posts you have.

How do I show all posts in one category in WordPress?

Simply go to the Appearance » Widgets page and add the 'Latest Posts' block to your sidebar. By default, the block will show your most recent posts. You edit the block settings and scroll to the 'Sorting & Filtering' section. From here, you can choose the category that you want to display posts from.

How do I show all items on one page in WordPress?

In the WordPress admin, go to WooCommerce > Settings > Products > Product tables. Add your license key and read through all the settings, choosing the ones that you want for your WooCommerce all products list. Now create a page where you want to list all products in a table (Pages > Add New.

How do I show posts on my WordPress Blog?

If you want your posts to show up on the home page and WordPress isn't already doing this for you, here's how you do it. In the WordPress admin, go to Settings > Reading. Find the section called Your homepage displays and select the Your latest posts option. Click the Save Changes button and go back to your home page.


1 Answers

Displaying all posts that has been published. You have to use post_per_page='-1' to retrive all the posts.

$args = array(
'post_type'=> 'post',
'orderby'    => 'ID',
'post_status' => 'publish',
'order'    => 'DESC',
'posts_per_page' => -1 // this will retrive all the post that is published 
);
$result = new WP_Query( $args );
if ( $result-> have_posts() ) : ?>
<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<?php the_title(); ?>   
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>

Hope so this will retrive all the posts as per your expectation.

like image 68
Naresh Kumar P Avatar answered Oct 02 '22 12:10

Naresh Kumar P