This is basic PHP. Just a note before I continue, never ever globalize variables. WordPress has already done quite a crappy job regarding this. Globalization is evil, because anyone and anything, knowingly or unknowingly can change a global variable. This makes globals a nightmare to debug. So in short, NEVER EVER globalize.
Whenever you need to pass something outside a anonymous function to the function, you should use the use()
keyword. As example, you can try
function () use( $the_query )
{
var_dump( $the_query );
}
EDIT:
In your code, you can do the following
fluid_grid( function() use ( $the_query )
{
?>
// Here goes the markup that should be printed out later
<?php
} );
Related Posts:
- How to use a custom post type archive as front page?
- Combining queries with different arguments per post type
- How do you get the count of posts in an archive page?
- Mixing regular and custom post types (with meta_query) on home page
- How to make a WP_Query search with custom post types?
- $wp_query->queried_object->ID throws warning: Undefined property
- how to filter by last name for custom post
- The Operator “NOT IN” Does Not Work In tax_query
- Display Custom Post Type Fields
- Related posts by author pagination not working on the production site
- Secondary loop pagination on custom post type single post gets redirected to first page
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy
- custom post type paging not working past page 3
- WP Query group/order by category name
- exclude custom post type by meta key in wp_query
- Query for custom posts with a specific tag slug
- Loop through categories and create tab for each
- WP_Query search posts by custom post type and custom taxonomy
- Unable to get post content from custom post type loop
- WP-Admin edit.php & post.php slowdown after import of 10k users
- How to dynamically attach pictures to a carousel
- Is it possible to apply a meta_query to one specific post type in a query with multilple post types?
- WordPress Orderby Numeric Value Not Working
- How to call a custom post type with WP_query
- How to add pagination to wp_query [duplicate]
- showing custom post types of a certain category only
- WordPress custom loop filter by meta_key and value with serialize data
- Show one item per category of a custom post type
- Storing posts from query and accessing later via AJAX call
- Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
- Mixing 2 custom post types with posts output in specific pattern
- Show only one post on custom post type archive
- How can I made custom taxonomies relationship?
- Why is this query not working? (Standard posts + custom post type)
- Pagination issue on category.php using custom post type query
- First custom field value (out of several) displayed twice after query
- How to get all tags of a custom post type by id
- Limiting posts_join, where, etc to a specific WP_Query object?
- How to make WP_Query not to show irrelevant posts?
- Create an archive page for custom post type with custom taxonomy
- WP_query – Filter by tax_query and meta_query using multiple select
- Create a list of recent Custom Post Types posts
- Empty search input does not return all posts
- How to sort a WP_Query by a custom field AND ALSO filter by a different custom field
- Undefined $post in wp_query
- Adding Multiple Post Types to Query [duplicate]
- Get current user id
- WP Query results showing posts outside of category ID
- tax_query (if the terms are empty)
- List latest post out of 2 custom post types
- How to count other posts not having specific taxonomy terms?
- Group by custom field value (start and end times)
- Running a custom query inside another cpt single and trying to grab a variable
- Get posts by category name
- WP_Meta_Query object with conditionals
- How to properly use Categories with Custom Post Types
- Problem while filtering by ‘category_name’
- Displaying Portfolio Filter by Category Order (alphabetically)
- Custom Post Type Query W/Category Dropdown
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- Pin posts to top of custom loop
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- WP_Query get always custom post_type for first
- WP_Query – How To Query Only Custom Posts With No Children of Their Own?
- Foreach result into WP_query
- Query custom post type and custom field by URL parameters
- meta query multiple values for the same key
- Custom post types – meta_query: search lesson which starts sooner
- Wp Query sort order from custom MetaBox
- Custom Taxonomy – fields
- CPT Loop, include taxonomies and disclude others?
- Custom Post Type Query by user id
- Query posts based on user preferences
- CPT post doesnt shows tags and category on backend admin page
- Adding a nav menu for a custom post type
- How to use costum database table for custom post type
- Most efficient way of showing children posts?
- Querying, storing, and using data from 2 separate custom post types
- date_query won’t accept day parameter, but will accept month and year for a custom post
- How can I use WP_Query argument ‘Like %..%’?
- Custom post type and custom taxonomies display
- WordPress custom post type
- Custom Post ‘Post Per Page’ Crashing Page?
- Custom post type single display is ommited
- Issue with permalinks for custom post type
- Query child posts on parents single.php?
- Paged within a custom content type template [duplicate]
- WordPress can only query up to 766
- Custom Post Query Combined with Conditional Tags
- Custom loop won’t work, can’t find problem
- Query by post type or category
- Get all custom_post_type posts + blog posts from one category in a single query
- Customising wordpress search and using $_GET[“s”]
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- How to exclude certain portfolios from a loop
- show the most recent date of all posts to display on front end
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
- How do I get parameters from the URL?