Your query is structured a little weird.
$my_query = new WP_Query( array( 'posts_per_page' => 5 ) );
if ( $my_query->have_posts() ) {
while ( $my_query->have_posts() ) {
$the_query->the_post();
// Your desired template code
} // Close while()
// Restore original Post Data
wp_reset_postdata();
} // Close if()
This should be all you need to set it up since WP_Query
pages by default unless you override it by setting 'nopaging' => true
in your arguments for it.
Note that after the while()
loop ends, the statement wp_reset_postdata();
is used. This resets the original post data to the defaults.
Related Posts:
- Text with special class as excerpt (or exclude special class)
- Split the_content into two parts
- Display Full Content Instead of Excerpt
- Excerpt being limited too early
- Using wp_trim_excerpt to get the_excerpt() outside the loop
- How can i limit the character length in excerpt? [duplicate]
- How to include line-breaks in the_excerpt?
- How to get the unfiltered excerpt, without […] or auto-excerpting
- Remove “Continue Reading” Link From the Teaser Excerpt Only
- Modify youtube video size on one page and show another size on different page
- Neither the_excerpt() nor the_content() works properly?
- Limit the_excerpt in the first point (.) of the sentence
- Excerpts that don’t truncate words
- Spacing within the excerpt
- Custom Excerpt is returning 52 characters and not 52 words
- How to remove “Read on” content in the_excerpt?
- the_excerpt Read More Filter
- How to get the excerpts of all children pages
- Custom excerpt showing first paragraph (with HTML formatting)
- Empty excerpt using wp_get_recent_posts
- Different ‘read more’ links
- The excerpt: Display text OR image OR video
- Read More for Excerpt not working
- Twenty Fourteen: Change Read More text
- wp_trim_words is trimming by character instead of by words
- adjust the_excerpt based on template page
- First letter cutting off in excerpt
- How to display links in excerpt? [duplicate]
- Getting the_excerpt to link to child pages [closed]
- Getting first 20 words without excerpt
- Change excerpt length of first post
- Display oEmbed in the_excerpt
- Remove Text within Header tags in the Excerpt
- Line in excerpt and max 5 lines
- Include post title in readmore link?
- Error when adding excerpt to the content through functions.php
- Excerpt using Read More Tag
- How to show post content before read more tag (excerpt) for password protected posts?
- How to apply excerpt length only on front end?
- get_the_excerpt() issues – returns the excerpt twice or not at all?
- Excerpt content
- Show excerpts of posts on P2 Home page
- How to change the length of excerpt() method?
- Removing h3s in excerpt output?
- get_the_excerpt without images
- the_excerpt() in content.php and get_template_part() in single.php
- Automatic excerpts
- How to properly show the Excerpt only if it exists?
- The excerpt doesn’t add Read more
- the_excerpt not displaying
- Display post excerpt instead of content, if available
- Show Excerpts In Twenty Eleven Theme
- Trimming a custom field to a length
- How do you edit the html of teaser excerpts
- Add custom read more to the_excerpt and
- Remove [ and ] from excerpt
- Excerpt vs content formatting woes
- Is it possible to use words as starting and ending points of excerpt parameters?
- How to replace get_the_excerpt with first N words of post article while stripping html
- How to edit a typo in excerpt?
- My post excerpt does not work
- The excerpt suffix won’t go away
- content summary of a post disappears If an images added at the beginning of the post. how to solve it?
- Adding […] string for a custom excerpt function
- Replace text in excerpt
- How to achieve two different excerpt types on one WordPress site?
- Manual excerpt length on recent posts slider
- Modify excerpt link
- Continuum Theme – Excerpt length
- Prevent Advanced Excerpt from Being Called
- Reblog WordPress to another WordPress?
- Filtered content appears in the excerpt
- How do i configure my content to show full posts?
- the_excerpt function not showing image
- How to enable excerpts just on the “Posts page”
- Excerpts not showing
- Keep excerpt from stripping URLs and enable autoembed for youtube ONLY?
- Help needed using wp_trim_words
- Nothing appears using get_the_excerpt() in category.php
- Excerpt of certain page to display on home page
- get_the_excerpt adding unwanted links to output html
- Excerpt functions is removing the forward slash on the url
- the_excerpt() doesn’t return the Excerpt field content
- How to add a new line to an excerpt?
- 2 posts same excerpt?
- Excerpt displays the current page excerpt not one being pulled
- Edit the excerpt before it is shown
- Is there a html tag filter for the excerpt?
- Add rel=lightbox to custom string
- Get content or excerpt of top rated votes @GD-Star Rating? [closed]
- multiple excerpt length and styles
- how to use the_excerpt for two post queries?
- How can I define the RSS feed content length?
- WordPress Post Format If Statement?
- Excerpt Problems
- Display a paragraph in the index page that won’t be displayed in the single post
- How to show excerpt field
- Get a raw value of excerpt
- Need to show post summary in sidebar
- Limited excerpt with readmore