Initiating new WP_Query($post)
shows all posts. Credit to @Latheesh V M Villa
Add:
$loop_query = new WP_Query($post)
Then change loop values like:
have_posts()
to:
$loop_query->have_posts()
loop.php
<?php $loop_query = new WP_Query($post); if ($loop_query->have_posts()): while ($loop_query->have_posts()) : $loop_query->the_post(); ?>
<article class="loop-template" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- article content here -->
</article>
<?php endwhile; ?>
<?php else: ?>
<article>
<!-- else content here -->
</article>
<?php endif; ?>
It appears you can leave everything inside the loop alone such as the_ID()
and the_title()
.
Great article at smashingmagazine here
Related Posts:
- Post X of Y in single.php / sidebar.php
- How to have different content in the loop and single
- Display all posts that were published before full post on single.php
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- Print Current Post Index number within Loop
- Should we trust the post globals?
- How to get posts published between a date and today?
- How to detect single.php (but not single-portfolio.php)?
- How set featured posts using checkbox in post edit screen?
- Get first post from wp_query
- Custom Single Post By Category
- Do we still need to include a “if (have_posts())” in templates?
- Display Random Author with Details in Sidebar
- WP_Query: Why is sticky post not first item in loop?
- Query *only* sticky posts
- Using single.php from plugin folder instead of default template folder
- Display all posts from specific categories on a page
- rewind_posts() – what actually the use of it, and where using is required or preferred?
- Custom permalink structure only for default posts
- Skip post in loop and mixin later
- Related Posts by Multiple Tags?
- How to show list of posts by author and category?
- $post>ID displays wrong post ID
- Override the default number of posts to show for a single loop?
- How do I create a link that will always show the latest post?
- get comments and get posts in loop
- How do I reorder (pop and push) items from WP_Query?
- How to exclude latest x posts from a paginated query?
- Getting the Next and Previous Posts Titles in the Sidebar?
- Display content from a specific category
- Reverse chronology of post listing
- Why do I need to use The Loop on pages (inside page.php etc)?
- posts page – different lengths of excerpt
- WordPress Number of Posts Not Changing With posts_per_page
- how to display full post with pagination on home page
- HTML code in Custom field
- Count singular post views automatically
- Looping through posts per category gives same posts for each category
- Find most recent authors
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Display All Sticky Post Before Regular Post
- Cannot access current post’s ID in custom plugin
- Can’t show comments count per post outside loop
- Get the author of the latest revision
- Single.php Active Category Class
- Specific loop in Shortcode
- Strange switch_to_blog() issue
- Show a list of recently viewed posts to a user
- Multiple loops in same page, without duplicate content
- loop not displaying posts on custom template page
- Repost post on specific date every year
- How to use alternate post layout at key points in post loop?
- Alternate custom content in the loop
- Showing random content / pictures from earlier posts in a sticky post?
- Search widget breaks when using multiple loops?
- How to Display Post View Count
- How to add shortcode tags in single.php [closed]
- Display all posts under child sub category in sidebar on post page?
- get_terms parent for current product only
- custom single.php not working
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- Load posts into sidebar and paginate via ajax?
- Display Latest Post from all Categories
- How to display different single post template based on author?
- How to show post(excerpt) from specific category on wp page?
- Auto Refresh Post List after X seconds
- How to show video from specific category on sidebar?
- The correct way to call posts with ajax
- WordPress menu that shows all posts in a certain category like w3schools
- how load content as pop-up using ajax
- custom wordpress post loop – hide iframe content
- Double count view in archive.php
- Divide Loop Into Days & Categories
- Converting multiple loops into one single loop with pagination
- Display posts with comments closed, with pagination?
- Disable single post page
- Group posts by year in loop
- How can I hide the sidebar from a specific post?
- how to know if the post has pagination () or not
- Remove arrows from previous and next link
- How would I get 1 latest post from a query for 5 posts?
- “next_posts_link” and “previous_posts_link” display me NOTHING
- While in “the loop”, detect if a post is the most recent
- How to disable single post view in wp
- Custom Post Templates
- Add code just after Post content
- Alternating post layout
- Check to see if specific loop has less than certain amount of posts
- Different style for most recent article
- Contact form 7 post loop [closed]
- Pagination on single post page?
- Differentiate between posts and pages in search results
- Related posts loop based on tags AND categories doesn’t work without at least one tag assigned
- Loop through all product posts?
- How to display different number of posts
- If Specific Post, Link Elsewhere
- Restrict post navigation to current sub menu
- How to filter posts that belong to a specific category only if that is the only category
- WP Query – duplicated posts once including tags in search results
- Sidebar links for different pages