For multiple category handling you need either category__in
or a tax_query
, for multiple custom fields you use meta_query
. The various options for both of these are covered in the WP_Query
codex page.
$args = array(
'posts_per_page' => 10,
'category__in' => array( 163, 165 ),
'meta_query' => array(
array(
'key' => 'a_field',
'value' => array( 1, 2 ),
'compare' => 'IN'
),
array(
'key' => 'a_fieldd',
'value' => 3,
'compare' => '='
),
array(
'key' => 'a_fielddd',
'value' => array( 1, 3, 5 ),
'compare' => 'IN'
)
)
);
$results = new WP_Query( $args );
if( $results->have_posts() ){
while( $results->have_posts() ){
$results->the_post();
the_title();
}
}
Related Posts:
- WP_Query – Order results by meta value
- Custom query with orderby meta_value of custom field
- Orderby meta_value only returns posts that have existing meta_key
- How to enable revisions for post meta data?
- Any way to add custom options to Gallery Settings?
- Can I query custom meta data through WP_Query
- Including custom fields in search?
- How to display all custom fields associated with a post?
- Change behavior of “Insert into Post” based on attachment metadata
- Sort posts by custom field numeric value using dropdown
- How to position a custom field before the editor
- How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
- passing argument to get_template_part() or a better way to code
- ACF – get_field() using ‘option’ as post_id not working
- Is there a way to do multiple ordering on a multiple meta_query?
- searching in custom meta field
- How to add upload field in a custom taxonomy?
- Display thumbnail from custom field
- Bulk move (or copy) from a custom field to the post content?
- Populating meta box with select-list of existing posts, and assigning it to custom post types
- Getting Custom Field data from a page hierarchy
- Custom contact form 7 select with custom values [closed]
- limit amount of photos uploaded per cpt post
- Problem with adding exta field in metabox in custom post type
- Move value of one custom field to another
- How do I add custom_meta_box_id’s value?
- little help with a mySQL query to wp database
- Add WYSIWYG to Image Description field
- How do I query for a post by custom field?
- Including Database Generated Pages in Site Search [closed]
- Calling custom profile fields?
- Get custom field label
- Show ACF fields only on certain page in the backend
- How to save media files under custom folder without changing wp-config.php or changing media settings
- Performance of storing multiple meta fields vs one JSON encoded field [duplicate]
- get_posts that match a user-specified value on a page
- Create Multiple File Upload Metabox in WordPress
- WP_User_Query pulling ACF to loop
- how to put a custom field value in variable
- Custom Metabox Not Saving
- How to add image attachment to post from a single meta key (Woocommerce)
- How to add the image URL from an external RSS feed and insert into a custom field?
- How to add Advenced Custom Fields In Single Post
- My custom backend codes shows up when i try to view my website
- Advanced Custom Fields dynamic update_field
- Custom Profile Fields move from BBpress to BuddyPress
- How can I output a list of values for a custom field, and posts with those values?
- Manipulate javascript code from custom made admin page menu
- Add additional ‘description’ field for defined roles / role metadata?
- Change the main loop WordPress impact on the server?
- How to get categories with posts by custom field value?
- Meta Query returns wrong number of posts
- How to hide a custom field if there is not a value
- Display Custom Field for a Specific Role, but not for Admin
- Walker class for sub-menu with ACF fields
- Hide text if one custom field out of two is empty [closed]
- Display custom field value part by part?
- Add custom fields to existing posts (admin pages)
- Multiple instances of TinyMCE are removing tag
- Echo the custom field value from the latest post from the ‘video’ post format?
- How do i get the attached images with custom value checked?
- How to disable Edit Post and Allow only Custom Field?
- Convert attachment ID into url?
- How to query an out put value?
- What’s the best way to implement custom widgets on a per post basis?
- Cannot save underscore custom fields in one wordpress installation using xmlrpc and underscores
- Diamond question mark in text after migrating content
- Retrive Image URL of Custom Fields in Theme
- Custom Fields Question
- do_shortcode close
- Search Results Page – Displaying Custom Meta Fields
- How do I convert all custom_field php timestamps in the database to js timestamps?
- Interrogate a page within a loop to check template type or custom meta data (Pages vs Posts)
- Display custom field value as a mailto: link
- wordpress get_post_meta / the_meta to output custom field value
- Make separate text boxes for separate WordPress Custom Fields
- Sort by an ACF field in a tax_query
- Allow HTML in Custom Metabox area
- Custom field metabox not showing in back-end
- How to display selected option from dropdown list in a metabox
- Load one page with parent and child pages
- Why can’t I get the correct post permalink
- Use a different catalog image than the featured image
- Login Api with Meta_key and Meta_value
- Ordering posts by custom fields
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- How to add an option to admin to add image that could be used as header?
- Bypassing a Form Options
- How to query posts that have certain post meta keys, and sort by meta key and/or value
- sort a custom field base on the date or anything
- How to implement jquery-ui autocomplete into custom fields?
- Add image custom attribute [closed]
- Retrieving custom field as shortcode
- Foreach giving one too many list items, how can I remove the last empty line?
- I used a custom field for header image and can’t get it to show up on posts
- Add custom fields to specific menus
- Add CSS class to posts with certain meta key
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP
- Best way for managing images of ads banners
- Crop custom image size vs actual size