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
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- ajax category filter
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- Pagination Not working on Home Page with 2 Query
- ‘posts_where’ filter not applying ‘WP_Query’ in `wp_ajax`
- Best Practice For Querying Grandchildren?
- Two queries on the same page with pagination
- WP_Query pagination not working in admin area
- Searching through different categories on different pages code is not working
- Update Loop with Form
- WP_Query’s “request” SQL Query
- Pagination working everywhere but the index page
- Show selected images on top in Media Manager
- is_search was called incorrectly
- How do I search inside specific taxonomies in WordPress
- Complex date range with WP_Query and BETWEEN
- How to loop for every result found in the_content() when using the search query?
- showing all search result in one template
- How to set pagination to work with ‘/page/’?
- WP_Query Pagination on multiple-loop page breaks WP or doesn’t show up
- AJAX search posts and pages
- WordPress Pagination changes my template
- Multiple Search Terms WP_Query
- WP Query Args – Title or Taxonomy Value
- Ajax WP_Query reutrns no results on author.php
- Pagination links missing for first link (1) and previous button? How to get pagination links to work?
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- How to return a 404 when custom query matches nothing?
- Multisite pagination issue by multi query archive 404
- Categorising search results based on Custom Fields
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- using pre_get_posts for search results not found
- Search posts missing a particular custom field
- Ajax future single post query doesn’t work when NOT logged in
- Append URL query to next post link in custom query
- Pagination is not working with custom query inside a homepage template
- Display single most recent post in category on every page of category archive
- Redirect Search to Form When No Product Results Are Found
- Issues with search after added meta_query
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Retrieve data from wordpress db via input and put those result in dropdown
- I need to run a AJAX Fuction from within a WP_Query but only works on first item
- WP_Query Pagination
- Searching not only by post name but also category
- WP_Query, Paginate by Custom Field
- JOIN filter doesn’t work in WP_Query in wp-ajax calls
- Why is my pagination /page/2 taking me to index.php?
- Block internal search queries with pre_get_posts and regex rules
- duplicated posts when using pagination
- Using Ajax and WP_Query to load more posts on category page fails
- Search Exact on WordPress – Relevannsi Solution Not Working
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- I have problems with the search query using multiple post types
- Add to search posts query array with post IDS which will appear first
- 404 page on custom search pagination
- Paging works correctly on local version, but not live?
- Pagination not working in custom loop WP_Query
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- Paginate nested query of child posts
- A very strange problem with search query
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- previous_posts_link not working in WordPress pagination
- Pagination not working with WP_QUERY
- WP_Query with meta_value_num and meta_query not paged correctly
- Custom Search Query – include only custom fields and title
- Search Query that Includes Custom Table
- Pagination with WP_Query not working
- wp_query pagination links producing 404
- How return normal search result using wp_ajax action for wordpress
- WP_Query breaks pagination
- paginate_links() with Custom Taxonomy
- Pagination problem with multiple loops on the same page
- Why does WP_Query not search for two ‘meta_query’ keys separated with OR?
- Refresh wp_query with no changes
- WordPress WP_Query Search (‘s’) With Multiple Search Terms
- Pagination only showed when no category is set in wp_query
- taxonomy-{term}.php terms pagination returning 404 after a certain page