Hook to get the query result after listing posts
Use the loop_end
hook – it passes the WP_Query by reference.
add_action( 'loop_end', 'wpse_263822_loop_end', 10, 1 );
function wpse_263822_loop_end( $query ) {
//* Make sure we're in the loop
if( ! in_the_loop() ) {
return;
}
//* Do something useful with the WP_Query
print_r( $query->posts );
}
Related Posts:
- why ignore_sticky_posts in sticky post query
- WP_Query by post ID doesn’t work if post is in custom post_status
- Tracing the life of a query
- Query all posts where meta value is empty
- WP_Query orderby taxonomy term value (numeric)
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- How to get post meta value and post in one query?
- wp query by search in titles only & put the posts in loop
- WP Query and order by particular specified IDs
- Woocommerce custom loop to show all the products [closed]
- Get the post permalink within the loop but without additional DB query
- Pagination 404 errors for author posts query on author.php
- List the 5 most recent child pages
- Meta-value query
- WP Query search for attachments and their exact title
- How to add another parameters to WP_Query?
- Display link to taxonomy archive only if it has posts with certain custom field values
- WP_Query compare with dynamic values
- WP Rest API max limit include parameter?
- Adding multiple post queries with parent and children to page – Best Way
- Programmatically set ‘meta_query’ for filter
- Display posts with date wordpress default
- WP Query Exclude and Start by Menu Order Offset
- Query total number of posts
- Category attribute not working in custom shortcode
- WP_Query Excluding pages with Order is 0
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- WC displaying products from category
- Show all post for a given category
- WP_Query create html structure
- How is WP_Query parsed to determine which template to request?
- pagination with numbers for WP_User_Query
- new WP_Query(), have_posts() return false in user_register hook
- Masonry, WP_Query & paged – first page repeating, second page not loading
- REST API: Limit Read Permissions for Default Endpoints
- Stuck in the query loop
- How to sort post by custom table value
- Filter wordpress post categories with jquery/ajax and pagination?
- Include current post into loop
- Is it safe to access the underlying mysqli object from \wpdb for custom queries?
- How to display the featured image for each post?
- How do I amend wp_query before it is run/executed?
- Post Thumbnail URL isn’t pulling into the background of div
- Is there a way to make this kind of loop shorter and nicer?
- WP Query ordering on a meta field for posts with a date in the future not ordering by datetime
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- Pagination on template page for custom query redirecting to index.php
- how to get Nearby zipcode
- Exclude authors IDs from WP_Query
- Reload Query Loop When FacetWP Uncheck [closed]
- WP Query Compare cutting off last 2 dates
- How to combine two WP_Query objects?
- Exec wp query in slow motion to avoid memory error?
- Wpdb->query result show 1 but is not an integer
- Loop 3 posts column wise and continue the loop into same columns
- Remove post type filter added by the plugin in the final query
- How to get more data of a post by wp_query
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- WP_User_Query orderby meta_val_num
- Query Taxonomy By Page Title
- WP_Query custom order and pagination
- How to change the default post type over the loop?
- Why is the value zero going in my custom database table?
- function wp() does not use meta_query?
- Determine if ID is page or post and query the ID
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- get_children() Archive Template
- What’s the best way to make a blog page on WordPress?
- Search filter between promo and exact price
- Populate select list with meta values from all posts of a Custom Post Type
- Exclude post from wp_query based on custom field boolean
- WordPress Meta Query Null Values Order
- WooCommerce WP_Query using tax_query returns no results (0 = 1)
- Bootstrap grid while loop
- search multiple keywords with wp_query using one query
- Order posts by tags count?
- Pre get posts sort by meta key returns no results if meta key does not exist
- remove_action – pre_get_posts – does not restore original query
- meta_query with relation = AND not working as expected when combining EQUALS with NOT EQUALS
- How to define a custom hierarchy for terms?
- WP_User_Query not searching numbers?
- Using something else instead of using 9 wp_query
- make query more simplest and in one query
- orderby in WP_QUERY – Use the order from the Dashboard
- Escaping WP_Query tax_query when term has special character(s)
- How to allow Readers to Select Post Order?
- Mathematical operations on custom field values? (updated)
- 423 queries in 6.098 seconds
- Load 3 posts in flexslider slide [closed]
- Issue with WP_Query (need a array of selected ID’s)
- Combine privileged users array with my current query
- How to exclude posts ordered by comment_count from subsequent wordpress loops using WP_Query?
- I cannot search users via user nicename
- Posts2Posts, wp_query and orderby issue
- WP_Query search by multiple meta key and distance
- Providing a function to override the default query
- WordPress Post Looping? [duplicate]
- Change posts archive ordering
- get_posts shows current post, not defined posts with args
- Can I use WP_Query to find a post with a particular menu_order?