One option is to fetch all of the posts to a single array and filter that array 50 ways. This would only generate the one query:
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'school'
));
To filter your array you would do something like this:
$this_state = "Texas";
$state_posts = array_filter($posts, function($results) use($this_state) {
return $results['state'] == $this_state;
});
From there, $state_posts
should contain a subset of $posts
where the State is Texas. Modify appropriately for each of your 50 groups.
This is untested but modeled on a very similar template I wrote last week.
Related Posts:
- How to List Events by Year and Month Using Advanced Custom Fields?
- Compare two numeric custom fields
- Advanced Custom Fields – Query Efficiency
- can’t get query to order posts by acf datepicker
- Order posts by custom field DATE value
- Get the_field of Advanced Custom Fields in a custom query [closed]
- Advanced Custom Fields – Relationship post foreach query
- Querying Advanced Custom Fields
- How can I get the name of term post meta value which equals term id
- Exclude in get_pages() based on meta field
- WordPress query: merge meta key (number) values and sort
- wp query multiple values > display a specific value first
- Modify a query using both a text field and a true/false AFC field
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- How to get comments by post ID?
- Is there a way of increasing the speed of this query?
- How can I query all users who registered today?
- Reversing the order of posts AFTER the query is performed
- what are the numbers between curly brackets in search query
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Search custom post type by meta data
- Multipart/formatted MySQL query problem
- Remove [gallery] shortcode altogether
- query multiple taxonomy and show post count
- Categories and products in random order
- add_query_arg() XSS Vulnerability
- Query set using tax_query with relation ‘OR’ modifies category object?
- Query by 2 values of a repeater ACF field
- Query posts by content lenght
- $wpdb doesn’t appear to work on page inside of a plugin
- Change searched term
- Query Posts By Post Publish Date, but sort by Custom Meta Key
- MySQL variable in query
- Search query -> Show all pages except certain template
- How to execute a SQL-query which contains multiple queries using $wpdb->query?
- Only show upcoming event or current events
- Why a URL with a query is always slower than that without a query?
- Maintaining Queries in URL
- How to orderby multiple meta fields with another meta query
- Query posts using meta_key
- Modify users.php query with multiple taxonomies
- MySql Query very slow
- wpdb query problem to access previous 3 days posts
- How to change the amount of posts previewed on a page?
- Problem when try to add ++1 for user meta
- query statement containing variable won’t execute
- How to get events using multiple custom meta fields?
- Get posts from category with custom query
- Random Page Rewrite
- How to pull posts into two columns with different image sizes using $counter variable?
- WP_User_Query with more than two custom meta values
- Select column name dynamically mySQL Query
- how do i register global query in template
- WordPress Mysql query and Duplicate
- How to “orderby” the first array in a meta_query that uses multiply keys?
- Sort query_terms_list for post_tags alphabetically
- Target a page with query
- List only parent attributes on woocommerce admin atrributes page
- Order posts ascending from posts in array
- Display data from phpMyAdmin with WordPress
- Add rewrite rule for archive search
- custom sorting media with multiple filters – error: not unique table/alias: wp_postmeta
- How can I get posts by 2 meta keys, prioritising one of them?
- SQL query to list all posts of specific post type with a specific set of associated postmeta values as a column
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- implementing my wp_query using $wpdb class
- Category_in return empty
- Query reversed when I use “category__not_in”
- modifying main query to query for ranges e.g. from 1999 to 2016
- How to reduce the load / no of queries on MySql Database
- Querying users by meta value and getting a strange answer
- Display result from custom post meta query
- Show certain number of post from tags
- Display Upload Author & Get Uploaded Post ID
- Display list of most recent grandchild (third tier) pages
- Query for distance OR taxonomy term
- How can I display a number to represent the order of post?
- Update vs Insert logic but the last key is always inserted?
- Apply ordering args to newly merged queried
- Sort order in get_posts [closed]
- Query unique author ids with published post of type job
- Wpdb generates too many queries
- Get blog id of subdirectory multisite blog from name – *outside* of wordpress request processing
- Custom Query for searching through custom fields
- Remove last comma from this query
- Query posts alphabetically within this function
- Conditional Tag Custom Querys?
- WordPress Unknown Query
- query posts only works on the first page
- Custom Query for wp_posts using wp_postmeta
- WP Query outputs three items within a div
- How do I troubleshoot Maximum execution time of 60 seconds exceeded in updating a Media File?
- update $wpdb one query
- Admin Post List table Query filtering “WHERE” for custom post type
- Ascending & descending posts on same page with IF statement
- Prevent executing query for wp_global_styles
- How to use a dynamic term id for the query block
- Meta Query compare with LIKE pulls similar post types: 55 and 155, and 1,155