Fixed it by changing the page’s name (more so the page’s URL) so that it did not match the post type name, which causes rewrite problems.
I also learned that previous_posts_link(); and next_posts_link(); as well as wp_paginate() rely on the query variable being named “$wp_query”, so “$my_query” doesn’t work.
Here’s my fixed code:
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
$args = array('post_type' => 'directory',
'posts_per_page' => 2,
'paged' => $paged
);
$wp_query = new WP_Query($args);
while ($wp_query->have_posts()) {
$wp_query->the_post();
// do stuff
}
previous_posts_link();
next_posts_link();
Related Posts:
- Is there a PHP function that can match anything after the given URL, so my IF statement will work in each instance?
- Pagination when using wp_query?
- Find out total number of pages in global query on archive page?
- Post_count only shows the number of results per page
- WordPress Pagination Not Working – Always Showing First Pages Content
- get_query_var function not working at all
- get_query_var( ‘paged’ ) not working outside of homepage
- Pagination returns 404 after page 20
- Combining two wordpress queries with pagination is not working
- How to paginate attachments in a secondary query as gallery?
- How to stop wordpress to make the default query?
- next_posts_link not working for loop called with ajax
- Why does pagination always break when used on any form of a home page?
- Pagination shows 404 after a certain number of pages
- Multiple endpoints in one URL
- Pagination not working for Custom search form & custom result template
- How to adjust found_posts so that it accounts for offset and pagination
- Pagination broken when merging search results with additional WP_Query
- Query with pre_get_posts to get pagination
- Pagination is not working using WP_Query
- Transient pagination not working properly
- Can not switch the queried post in pre_get_posts hook
- Woocommerce custom loop to show all the products [closed]
- How to bring specific post to front of wordpress loop?
- Pagination for custom query on single.php
- Intentionally exceed max_num_pages on main query without getting 404?
- Get rewrite result
- Pagination 404 errors for author posts query on author.php
- Pagination problem after WP_Query with tag filtering
- Too many posts cause slow load when paginating
- Pagination stops at page 6
- Paginated HTML Sitemap
- How to output different posts per page?
- Multiple WP_Query loops with Pagination Not Working
- Posts loop with pagination on a single post page
- Offset Page Loops and Pagination
- Pagination is broken and I need help fixing it
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- WordPress add_rewrite_rule() cannot visit lower url levels
- The pagination on index.php doesn’t work on a first page
- paging in WP_Query on static page
- Serve specific “template” page at any URL that ends in its slug
- pagination with numbers for WP_User_Query
- WordPress pagination not working using WP_Query
- posts_per_page not working for first page of pagination
- Pagination on static Posts page
- WordPress Blog Posts with Pagination inside a Page/Post
- How to cache wp_query with pagination using transients?
- Pagination only won’t work in author template
- wp query error while paging the posts
- “paged” in WP_Query returns 0 posts
- Pagination on template page for custom query redirecting to index.php
- Notice thrown when creating numeric pagination on custom query
- Paging + WP Query
- WP_Query custom order and pagination
- Second loop pagination changes URL, not content
- Unable to paginate a custom page query
- Query Not working as expected
- max_num_pages says 4, yet I am only able to navigate to the third page
- Paginate pages with dynamic query
- filter posts by meta key with pagination
- Trouble Making WP_Query paged
- Pagination problem by using WP_Query
- Ajax (jquery) wp_query pagination returns -1
- Function the_posts_pagination() not compatible with WP_Query arguments
- adding pagination to a foreach loop in wordpress
- paginate_links appearing on page but it doesn’t actually paginate – pagination on a static page with a dynamic `post_type` argument on a static page
- Pagination of custom page with custom fields query
- pre_get_posts pagination not working
- Pagination not working on archive.php template?
- How to allow a variable with “/” in wordpress url
- Pagination inside the blog page not working
- Pagination Shows Up But Won’t Work on Custom Gallery Page
- Custom Query Pagination not working on static front page
- WordPress search page pagination displaying but not functional
- Paginated Post List on Front Page
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Rewrite rule pagination on different url levels
- Pagination returns 404 after page 20
- Archive – Show Page Month Headers
- Query post Pagination Problem
- Pagination for custom query throws 404 errors on last pages [duplicate]
- Pagination is not working on custom query inside a custom home page template
- Horizontally paginate through sets of blog posts?
- Pagination not working in some author pages
- Pagination error WordPress multiple loop
- Comments orderby comment date not working
- Switched from query_posts to wp_query, pagination no longer working
- Pagination With Custom WP Query not functioning
- Ordering Custom WP_Query loop by meta key value with pagination
- Loop being strainge
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- Pagination in custom query not working [duplicate]
- paginate_links() on page (shortcode output)
- WordPress Post Looping? [duplicate]
- Pagination showing same posts despite changing page
- Pagination with Custom Post Type not working on index.php: I get a 404
- Show number of posts AND number on current page (cannot make it work)
- Search results stuck on page 1