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
- get_next_post() and get_previous_post() return wrong posts
- Define a wordpress constant through plugin functions?
- Show all posts in sidebar in single.php
- Split WordPress Latest Posts in Multiple Columns and Rows with one single loop [closed]
- Avoid duplicate post from same Taxonomy
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Display post from current category and same tag?
- Why orderby=”date” does not support manually changed posts?
- Static page does not show my posts
- Alternate row and columns every X posts
- I am unable to publish/update post
- Inserting custom data to the_post() during loop
- Custom WordPress Theme: Publish Date and Display Date for posts right beside each other
- Adding specific post category between posts in loop
- Display post category in foreach loop with category link
- How to get post bulk edit action trigger and get edited post ids?
- How To Get Posts With A Specific Word
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- How do I restart my loop with get_next_post()?
- How to display posts on a static page? (like search loop)
- How to show single post page as home page
- Child_of not displaying all children posts.. via get_posts
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Multiple loops are not reset
- Displaying Latest Posts on a Page
- Display all posts that were published before full post on single.php
- Display post lists in 2nd paragraph
- Blog page not working
- WordPress Loop – Next 3 Posts
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- problems with loading posts in a table-row
- Blog page pagination is not working after using the offset argument
- How to display the link (title) and thumbnail post?
- Underscores Theme Unit Testing – Catching Untitled Posts
- get_the_excerpt() is not working as expected – returns wrong text
- Posts will not display on page-mypage.php
- WP Query – Posts Per Page not working in combination with category__in
- updating a post doesn’t trigger a function
- Hide a specific category in admin All Posts page (WordPress)
- Prevent Delete Attachment by URL or When Submit
- How to use format post in a pertinent way
- More then one menu items are assigned with “current-menu-item” class
- What hook do you use to update a post?
- Pausing and Resuming WP_Query results
- Pulling in post category and children within category
- Updating post data on save (save_post vs wp_insert_post_data)
- Unable to restore from backup – how to obtain old blog posts?
- Post Loop Missing Most Recent Post
- Trying to use AngularJS with WordPress without any API
- How to : pagination in 3 different custom loops on the same page
- Pagination with an array of post objects?
- Sharing post from archive page (loop) doesn’t work
- Get Image tag from content of post
- Start WP Pagination From Number 1 in URL
- Disable sticky option for specific categories
- How to add tags (custom taxonomy) to post class css?
- List authors with the last post title and order by last post date
- Listing Specific Categories from Current Post with Depth
- How to exclude visited posts from loop
- Use two different post_per_page limits with infinite scroll
- Highlight static blog page link in header
- wp_query random post
- How to make the first post in the loop be styled like a “new / featured” post?
- “Right Way” to make custom Loop respect reading settings inside admin panel?
- How to setup a query to output posts by groups of five?
- Redirect to another page using contact form 7? [closed]
- Only display sticky post or latest post in custom loop
- How to order posts in an arbitrary order?
- How to create a template for Pages?
- How do I stop the loop from repeating in my category template?
- get_the_category listing in hierarchial order
- How do I do a page break?
- How many posts does the loop return?
- Display Posts on Custom Page
- How to make a sum of all posts displayed in a loop
- Possible to alternate between two loops
- Exclude current custom post on single post
- Wrong post title displayed from loop
- What happens if I delete all the rows that represents a post revision from the posts table into WordPress database?
- Get Value of Post before
- why does wordpress ignore the post args?
- Multiple Loops Breaking Pages
- add to end of post in the loop with plugin
- Block editors annoying warnings