From the PHP manual:
Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus:
'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
Hence before diving into your code further:
-
It would need much more than
$arr_name = str_replace(' ','_',get_the_title());
to make this fail-safe. Currently, your code is bound to fail as soon as the page title contains any non-alphanumeric characters. -
Because of the above, among other reasons, I’d strongly suggest you reconsider the general architectural approach. Ask yourself this: Why would you need variable variable in the first place? (I don’t see a reason and I doubt this to be the most viable solution, even if a valid reason exists.)
Related Posts:
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- What kind of object type is WP_Query?
- How can I save an array from a random post sequence for later use?
- Getting an array out of WPQuery
- assign 2 $args to one wp_query
- Use Transient API to cache queries for all posts in all categories?
- WP Meta Query for some meta (array) values
- meta_query with array as value
- Placing a div or img in between a post array using WP Query [closed]
- Show one post per author and limit query to 8 posts
- How add a custom posttype name using ACF field to a query post array
- How can I get an array of all IDs from the current queried object?
- How can I pick a single post from the latest 3?
- WP Query for variable taxonomies
- Minimize database queries to user tables?
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- Adding an array from a query string to a WP meta_query
- Weird orderby => post__in issue
- How to list custom fields as headers and list all pages sharing that custom field under it?
- Query all posts if multiple meta key don’t exist
- Get posts by list of post IDs ordered by those IDs?
- Removing duplicate values between two wordpress queries
- Include current post into loop
- Combine results of multiple WP_Query to resemble single WP_Query
- How do I turn these values from MYSQL into an array
- Does meta_value (array) work with ‘orderby’?
- search serialised meta_value for date value?
- Combine 2 arrays in a query parameter
- How can I comment comma-separated array values?
- How do I add a relation parameter to my filter query?
- construct complex queries with WP User Query
- Get a list of ACF Repeater-Fields as array
- WP_Query with page_ids in arguments without a result
- Related Posts Excluding Certain Categories
- Query using string from custom field as array value
- Multiple meta query from array
- Category based on post id
- How to get specific string in explode array?
- How to avoid filling up an array each time I run a WP_query?
- Remove from array in WP_Query loop
- meta_query returning excluded result
- Combine relationship posts with existing wp_query
- Counting instances of words in the results of a post query
- sanitize_post() is not sanitizing Post Object
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- WP Query by 4 different taxonomies
- Trouble with serialized metadata
- What code to use in an array to call the current sub-category?
- WP_User_Query Orderby Not Working
- Loop through array of pages
- Repeat array inside array through while loop
- Sorting Posts by Taxonomy thats not within the query’s $args
- Related Post by Tags Code
- date_query problem
- WP_Query: Meta_Query with serialized value (or a workaround)
- how to query for meta_value have array
- wp_query – Modify $query to include duplicate content
- Iterate through ID’s in loop
- How to get several fields from wp_query?
- How to sort a WP_Query array by post_name after an array_merge();
- Issue with WP_Query (need a array of selected ID’s)
- WordPress WP_Query Array Custom search via taxonomies
- WP Query posts__in not working with array
- Sort Posts with custom meta key by default which is currently set as optional
- Dynamically create array from page title
- WordPress Query Returning Every Post
- Creating Custom Query
- How do I have multiple metaqueries inside one wordpress query
- I want to place a post before all others from an ACF boleen field
- wp_query, calculate with two dates when ‘key’ is text format
- How to trigger 404 for custom query var?
- WP_query taxonomy + get all posts with two terms from same taxonomy
- How do I create my own nested meta_query using posts_where / posts_join?
- Best Practice For Querying Grandchildren?
- How to prevent queried posts from being added to cache?
- How can I query posts with newly uploaded images?
- Conditional arguments WP_Query for post custom fields
- Random loop with code to prevent duplicate output returns no output at all from time to time
- Single meta_query query using OR instead of AND in request’s WHERE statement
- How to loop for every result found in the_content() when using the search query?
- How to restrict the search fields for a specific post type
- Pagination links missing for first link (1) and previous button? How to get pagination links to work?
- Query with relation and one without relation using multiple taxonomies?
- WP_Query with different postmeta filter for each categories
- Automatically Query Parent Taxonomy
- Shouldn’t I be able to modify the main query by this filter?
- Get all posts which was posted on X Days WordPress
- wp_query comment and meta query
- Limit number of posts in WP_query per month
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- how to translate countries output from wp database?
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- SELECT TOP 1 in wp_query for each groupby meta value
- Get unique post by meta value using wp_query
- XMLRPC pingback.extensions.getPingbacks not work with parameters
- Get posts meta_query by repater field
- How can I use two custom fields in WP Query
- Letting users sort posts
- Related posts with WP_Query
- How to replecate the _fields parameter in custom REST api endpoint