The original request that loaded the page you are making the AJAX request from ended as soon as the page was sent to your browser. That connection is closed and it is gone from memory.
When you make an AJAX request, it’s a new request, so $wp_query
is empty because you haven’t queried anything. You need to create a new WP_Query
instance and query the database, passing whatever query variables you want to set in this query via your AJAX function.
Related Posts:
- Search – Ajax – Alter Query Parameters with Pagination
- Post_count only shows the number of results per page
- next_posts_link not working for loop called with ajax
- Pagination not working for Custom search form & custom result template
- Pagination broken when merging search results with additional WP_Query
- Pagination wont work with search results template [duplicate]
- Add custom search results to main WP search [duplicate]
- WP_Query ajax loader detect end of posts
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- wp_query ‘s’, search filter with pagination is not working
- how to handle multiple ajax wordpress queries?
- WordPress pagination not working on template search.php
- Cutom wp_query for geolocation search, pagination not working
- How do I get my custom query to work with search results after the first page?
- Ajax (jquery) wp_query pagination returns -1
- Pagination repeating posts on search results
- Filter admin ajax data by url query
- WordPress search page pagination displaying but not functional
- Order & Orderby clause not working with custom query
- WordPress WP_Query offset parameter not working with search parameter
- Duplicate posts showing up in loop using infinite scroll
- Search results stuck on page 1
- AJAX multiple search boxes not merging with array merge
- Pagination when using wp_query?
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Can I force WP_Query to return no results?
- Find out total number of pages in global query on archive page?
- Multiple WP_Query loops with Pagination
- Pagination with custom SQL query
- WordPress Pagination Not Working – Always Showing First Pages Content
- WP Query where title begins with a specific letter
- AJAX search on post pages by custom post type
- get_query_var function not working at all
- get_query_var( ‘paged’ ) not working outside of homepage
- Pagination on a WP_query not showing navigation links
- Different ‘posts_per_page’ setting for first, and rest of the paginated pages?
- How to paginate wordpress [gallery] shortcode?
- Pagination returns 404 after page 20
- paginate_links() adds empty href to first page and previous link
- Search custom taxonomy term by name
- paginate_links ignore my format
- Combining two wordpress queries with pagination is not working
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Custom WP_Query order by post_meta and (author) user_meta
- wp_query->max_num_pages always returns 0 on custom post type
- How to paginate attachments in a secondary query as gallery?
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- ajax category filter
- WP_Query and Pagination on a Static front page
- Tracing the life of a query
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- Want to redirect if search query match exact title of any post
- Why does pagination always break when used on any form of a home page?
- Ajax and WP_Query/tax_query parameter
- Pagination with 5 posts per page
- Load more AJAX on WP Query
- Pagination shows 404 after a certain number of pages
- Pagination custom query
- How to support multiple search terms query within one process?
- Pagination/infinite scroll with WP_Query and multiple loops
- get data from wp-query, outside the loop & without url change
- How to adjust found_posts so that it accounts for offset and pagination
- WP_query and pagination?
- pagenavi with merged wp_query [duplicate]
- Add and in the header while looping over custom query in page template
- pagination doesn’t show up for custom post type
- Custom search form with empty parameters
- Pagination causes error 404 when used with front-page.php
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Pagination with Custom Post Type not working on index.php: I get a 404
- Pagination on custom post type not working
- Filtering product search results using tags
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- Refresh wp_query with no changes
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- How does Show Posts based on a keyword search work in WP_Query
- Pagenavi with archive page
- Show number of posts AND number on current page (cannot make it work)
- WordPress WP_User_Query ignores the `meta_query` when called from an Ajax function
- Search query alteration not working for meta values
- AJAX search function resets wp_query vars
- Limit paginated result set to a maximum number of posts
- WordPress Ajax search filter on dropdown select
- Custom Taxonomy in custom REST API search
- Advanced Search – Is this possible?
- How to include custom fields in wordpress search
- Pagination only showed when no category is set in wp_query
- Extend search query to search meta keys values based on search string
- taxonomy-{term}.php terms pagination returning 404 after a certain page
- Removing filename searches when searching attachments
- Modify WordPress Search
- Rewrite URL custom search query
- Multiple WP_Query with pagination shows Page/2 content on the remaining pages
- Multiple queries and pagination
- Applying a custom query for the AJAX “us_ajax_grid” function (from WPBakery)
- Optimizing AJAX Query with Large Database
- WP_query with ajax filter not working with input fields
- WP_Query offset returning duplicate posts from previous loops with AJAX