Can you please let me know why this is happening?
A loop like yours assumes the data from the “main query”. You’ve created a custom page template so the main query on that page is going to be the single “TestPage” data. That is the way it is supposed to work. That is, if ( have_posts() ) : while ( have_posts() ) : the_post();
doesn’t always give you the post archive data.
To get the posts you’d need to create a new query and loop over that. Like this:
$newq = new WP_Query(array('post_type'=>'post'));
if ($newq->have_posts()) {
while ($newq->have_posts()) {
$newq->the_post();
the_title();
}
}
You should probably look over the Template Hierarchy carefully, because this may not be the way you want to go about things at all.
Related Posts:
- how to display full post with pagination on home page
- Cannot access current post’s ID in custom plugin
- page.php showing loop of posts and not page content
- Exclude category from
- how to handle the loop using filling bootstrap grid structure?
- I can’t find the relevant part of the loop in my theme file. How do I find the full content with “More…”
- Moved a website and excerpts don’t work for old posts
- Display post order ranking within wordpress loop
- Post are not showing up
- How to show the posts list into a static page? Problems to use the loop into a static page
- wordpress taxonomy results
- The post order is different for logged-in and non-logged-in users? [closed]
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- WordPress Ajax load doesn’t work
- Do we still need to include a “if (have_posts())” in templates?
- Query *only* sticky posts
- How to get Images included in Post
- Manipulate post category after time
- Post & edit a post from front end along with upload, dropdown, and other inputs
- Can’t show comments count per post outside loop
- How to change post status from publish to draft using hook in wordpress?
- Show a list of recently viewed posts to a user
- Alternate custom content in the loop
- Displaying Page Title on index.php
- How to enqueue scripts depending on post formats?
- Paging on a future post loop?
- Auto Refresh Post List after X seconds
- Display posts with comments closed, with pagination?
- Related posts loop based on tags AND categories doesn’t work without at least one tag assigned
- Static page does not show my posts
- How To Get Posts With A Specific Word
- WordPress Loop – Next 3 Posts
- Blog page pagination is not working after using the offset argument
- Underscores Theme Unit Testing – Catching Untitled Posts
- WP Query – Posts Per Page not working in combination with category__in
- Pulling in post category and children within category
- How to add tags (custom taxonomy) to post class css?
- Listing Specific Categories from Current Post with Depth
- How to exclude visited posts from loop
- Redirect to another page using contact form 7? [closed]
- get_the_category listing in hierarchial order
- What happens if I delete all the rows that represents a post revision from the posts table into WordPress database?
- add to end of post in the loop with plugin
- How to add a class to edit_post_link?
- Loop don’t work within single.php page
- WP_Query with custom post type ID
- Add custom text automatically on each post
- Getting blog pagination to work on page set as front page
- Make loop inside slider divisible [closed]
- Display current post position in Elementor Posts widget
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- Some doubts about how the loop work (trying debugging it)
- If custom field is empty, use one from a previous post
- How can my plugin display a populated new post window
- search content of pages and list in wp-admin
- Limiting the amount of posts retrieved by the loop
- Plugin is creating posts twice
- Display 3 posts with different HTML markup using a loop
- Insert specific information to a posts of a predefined category
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- How to repeat a loop after 4 posts [duplicate]
- How to separate each individual blog post?
- Am getting duplicate data from get_posts()
- Is there a way to define the $post var outside the loop?
- Only the most recent post is showing on my category page (working on localhost, not live site)
- How do I add filter with woocommerce categories?
- How can I see $post object in frontend from functions.php?
- show loop id post , only first id can read
- Can I Paginate Post after every 25 tag?
- Alternative content between posts no repetition
- Start loop from specific post ID
- Display new posts categories in separated divs
- Wp_query loop is not working as it should
- Maximum number of posts per page before affecting performance?
- Trim excerpt to first paragraph
- Problem with wp_insert_post()
- How to control Post view count incresing in sidebar widget posts too?
- WordPress loop uses unmodified posts array, why?
- Add row after three columns
- Modify WordPress loop after it has been run
- Skip posts, but keep posts per page
- Multiple Post Repeat for Related Post Loop by Category
- index.php is only displaying current month’s posts?
- Loop doesn’t display posts. It displays a link to the home page instead
- Grab next post title in archive page
- Where should get_post_meta() go to get $post->ID get_post_meta() is empty and $post->ID & get_the_id() are working
- Getting posts from multiple users?
- Show post if in category
- Displaying categories items among posts
- Which hooks are essential for post templates?
- Show all posts in category
- Hide the contents for specific post
- First post in loop displays twice
- Wrap every 2 posts
- Convert HTML5 to WordPress theme
- Error 404 blog/page/2/
- What function does the loop of displaying posts?
- What template file is used by default for posts?
- Is there a block to print post link standalone in a block theme?