It looks like you are attempting to create a secondary archive/index page on the “events” template, but haven’t modified the main query for the page. Without that, you will only get results for the one page. Try:
function events_wpse_206465($qry) {
if (is_page('events') && is_main_query()) {
$qry->set('posts_per_page',5);
$qry->set('post_type','events');
}
}
add_action('pre_get_posts','events_wpse_206465');
Or create a new query:
$args = array(
'post_type' => 'events',
'posts_per_page' => 5,
);
$myq = new WP_Query($args);
if ($myq->have_posts()) {
while ($myq->have_posts()) {
$myq->the_post();
the_title();
// and so on
}
}
Related Posts:
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- the_title() shows title of the first post instead of the page title?
- How to place comments_template(); outside the loop?
- Endless loop with wp_insert_post and wp_update_post
- How do I prevent one of two multiple loops from repeating on a second page?
- Hook into the loop via a plugin, and output something after every X post?
- Two custom loops, pagination, offset
- What exactly defines a Main Loop and a Secondary Loop?
- Loop code is displaying pages but not actual posts
- How are both HTTP and HTTPS versions displaying?
- Access to Media Library
- Getting two wp_link_pages output
- How do you split multiple-column loop on category archive page?
- How to Loop within a Loop (Display Children and then Grandchildren)
- Run The Loop over array of post objects
- Enable infinite scroll on single.php [closed]
- How to loop through ALL pages?
- Does get_template_part pull data once in a loop?
- Get titles of all posts with current tags except current post
- How to retrieve “sticky” post outside the “loop”?
- Creating a multi-taxonomy query, excluding the newest (read: highest ID) taxonomy term
- Show a different post every 3 days [duplicate]
- Targeting a Certain Post in Loop (CSS)
- Using get_the_excerpt() Before The Loop
- code suddenly appearing from my tempate second loop
- Display most viewed post from last 30 days is not working correctly
- What is the maximum number of posts a WordPress loop can work with?
- wp_query inside the_loop
- How to go about combining dropdowns / filter queries?
- Split loop to load WordPress gallery into Bootstrap modal and carousel
- woocommerce get_price_html not pulling in correct price
- How to fix pagination for custom loops?
- WordPress Rewriting the DOM?
- How to display posts by vote count and if no value continue with latest posts with no votes?
- Sort results by groups of numbers and letters
- Modify the main loop to display current month / year
- Modified loop-single-forum.php to work inside of a sidebar Widget, not working on some site pages
- Basic multiple loops only displaying first loop
- Display post list with different styles
- Both a page loop and posts loop on the same page
- Loop for sticky posts
- WordPress Blog has an infinite redirect loop
- Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
- Array ids post to function have_post
- How to create bootstrap grid loop?
- Is it possible to reverse the order of a list of posts pulled from a loop?
- Give each posts in a loop a number in sequence
- How can I access specific posts brought back by query_posts?
- Put multiple custom loops on same page
- Contact information footer
- custom post on homepage
- Multisite foreach loop returning only one result
- get_comments with post_status ‘public’ retrieves NULL result
- Loop is crazy – one row displays wrong count of posts [closed]
- I have broke my pagination, same posts on all pages (index.php)
- Filter existing hook using parameter and foreach loop
- Run “the loop” in a random order
- Search page loop banner image issue
- Hook to main query with filters based on custom fields
- Using has_tag() outside loop
- Getting selection of posts based on loop variables via Ajax
- Why would this code work locally but break online?
- Why would a completely normal loop give offset errors and maximum execution time errors?
- Avoid WP_Query’s duplicate posts with taxonomies
- How to create multiple loop in archive page?
- Offset for Loop
- Properly loop through and paginate page on each function call
- Why does my WP_Query pagination on a custom page.php only loads the homepage?
- WordPress finding posts on 404 page
- Get a Post Loop based on Logged in User information into a Shortcode
- Loop keeps showing the same post even when I click on a different one
- Query users and count totals based on meta values
- php loop error for count posts in category
- display post pdf attachments in side bar with link text
- Display all the terms within a custom taxonomy
- Last post in loop when even
- Use the loop to check if DB record exists?
- Split Content and Gallery
- Adding comma to while loop wpquery output
- Search – Check if post is a page on search page
- How can I make this iterative conditional within the Loop work via function?
- Active class for my flexslider in WordPress
- pre_get_posts main_query not displaying after applying tax_query filters
- WordPress loop only displays 5 articles max?
- setup_postdata in “loop-handling” php file called via $.ajax
- Secondary loop cuts off at 10 posts?
- get_template_part() to render single page Theme
- Can’t see custom field after the Loop [closed]
- Showing related posts (custom post type) outside of the loop
- get all page templates
- Paged homepage – requirements?
- Least Number of Loops to Create Custom Homepage?
- The Loop for my theme with static front page is not working
- WordPress loop: Display if posts exist
- Posts Loops To Display Specific Posts Inside Page Template?
- Use callback function in AJAX pure javascript [closed]
- Showing ads after posts in home page
- title not being printed within html tag [closed]
- Prevent duplicating specific column from database table
- Hide old posts each year