You could use a taxonomy query to make it cleaner and easier to read; I’m not sure if this would be any faster than the way you’re doing it, though.
$args = array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'name',
'terms' => array( 'Europe', 'local' ),
'operator' => 'IN',
),
array(
'taxonomy' => 'category',
'field' => 'name',
'terms' => array( '2017', '2018' ),
'operator' => 'IN',
),
),
'per_page' => 10000,
);
$posts = get_posts( $args );
…should get you any posts (well, the first 10000 posts) that are in ( ( 2017 || 2018 ) && ( Europe || local ) )
. (I think; the code is untested, so you may have to tweak it.)
Related Posts:
- Why Does get_posts() Return an Empty Set?
- get_posts / WP_Query Memory size of 134217728 bytes exhausted
- How to check category name available or not
- Making Woocommerce optimized for more than 500k products
- How do I query posts and have their related taxonomies returned in the results?
- add_action hook for completely new post?
- WP_Query leaking absurd amounts of memory
- How to return only certain fields using get_posts()
- Fatal error: Class ‘ms\WP_Query’ not found on plugin initialization [closed]
- Register custom query args parameter for WP_Query()
- How to add multiple custom URL variables?
- Getting wrong relationship value in $args in wp_Query?
- get_posts with multiple categories
- Check for featured image in WP_Query
- How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?
- How to ensure “the_content” filter runs only for the main displayed content?
- add_filter and remove_filter added before and after wp_query
- How can i list current author’s categories?
- How to Make a Category Always Selected?
- How to get all images and their thumbnails from wp media library
- anything like add_meta_box for categories?
- Calling clean_term_cache() fails when called in the same plugin that creates terms, succeeds when called separately?
- Missing “category_children” option when dynamically creating categories via a plugin
- How to create a dynamic page based on form data with a plugin?
- Can we create a category list page in WordPress?
- How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
- WP Query group/order by category name
- prevent showing posts of an specific category in admin posts section
- Handling form request from plugin file
- WP_query category__in not working, only pulls from first category
- prevent post to have multiple categories in my plugin
- Cannot search post by taxonomy
- How to get orders with used coupon in WooCommerce
- WP_Query with tax_query, order by most ‘matches’
- Ordering posts by metadata
- How to print raw query from WP_Query class just like in CodeIgniter
- WP_Query returns no results
- Show add_meta_box by selecting a specific category
- Finding posts containing matching array elements in a meta field usign WP_Query
- Which are the hooks run before/after when a category’s deletion?
- Create a custom display order in the main menu
- manage_posts_custom_column, showing serial number using increment in loop
- Error : “Cannot use object of type WP_Post as array in”
- Proper way to run wp_query from inside a plugin
- using new WP_Query in save_post function alters $post
- how do you prevent showing a particular category on the admin dashboard for specific user roles?
- Slow WP_query due to nested wp_query. Need Suggestions
- get_posts() not working when accessing with a custom user role
- Is it possible to change a term slug before being saved to the database?
- ORDER BY wp_post custom column name in wp_query
- wp_insert_category() setting the ‘cat_ID’ gives not array error
- How to create database table, add data, update and delete using wpdb via plugins?
- get post attachment using ajax
- Elementor custom Query with ACF fields to show matching woocommerce products custom fields
- Send push when new post is published in a certain category
- WP_Query filters
- How to fetch only current hour posts?
- How to get Metabox custom field to show checked if value is updated using post meta query?
- WordPress pre_get_posts with combined results of two queries (OR)
- How do I get the sub categories of the parent when in a sub category?
- Search: how to extend the existing search to include a custom table
- How to get post content by get_posts function?
- Why does my widget break other widgets?
- how to get all the child category name in a specified category name?
- Filter Categories widget to allow custom sorting?
- how to invoke wordpress API from other existing PHP system
- Redirect to another page using contact form 7? [closed]
- What’s wrong with this post__not_in argument?
- How I can use order by of the custom post title?
- Function/Class to list categories with checkboxes
- Delist entries in the_loop
- How to query children by post name/slug
- 400 Bad Request, in wordpress theme development, wp_ajax
- Prevent WordPress automatically processing certain URL queries
- How can I show posts for a single category?
- Check if post belongs to any category
- Store custom meta box data as serialized array
- How to display the categories on page using shortcode?
- How to display the category id along with category name on categories list?
- how to load the comment template from a plugin
- How remove trashed WooCommerce orders from wc_get_orders() result?
- add_action pre_term_description vs. pre_category_description
- How to show parents of current page category, excluding the category?
- Auto-complete or auto-suggest from stored data in database
- How to get posts by category and by choosing a taxonomy term?
- WP Dropdown Categories, display subcategories but not grandchildren categories?
- Get post thumbnail in WP_Query
- How to properly use Categories with Custom Post Types
- Pagination not working with custom wp_query
- Get Posts by IDs (optionally)
- Load stylesheet in edit category page?
- How to relate the Category to user?
- Adjust query on single
- How to exclude categories from get_categories() select list inside a widget admin panel
- $_GET vs get_query_var()
- What is the meta_query key name for the woo product average rating? [closed]
- get the queried_object of an url
- Return custom product in ajax call loop
- How to get recent one post from each category on home page?
- A better way of getting draft posts that has a particular post meta using get_posts function