This will get the posts filtered by custom field and its value based on categories.
$args = array( ‘post_type’=>’post’,
'category__in'=> array(6, 7, 31), //category id
'meta_key'=>'keys', // customfield name
'meta_value'=>5, // customfield value
'posts_per_page'=>-1,
'number_posts'=>-1 );
$s = get_posts($args);
foreach($s as $e ) {
echo $e->ID.'<br/>';
echo $e->post_title.'<br/>';
}
Related Posts:
- Add custom field to the archive page?
- Filter archive.php by custom meta
- Date, Time, and Timezones
- Archive sorting functions by custom fields (front-end)
- Order by custom field date?
- Order by custom field date with ASC order
- Ordering posts by anniversary using only day and month
- Localized Date Format for Custom Field
- How can I query on the year part of a complete date in a custom field?
- Displaying posts with only upcoming dates according their custom field date value
- Meta query with multiple custom fields for archives page ordering problem
- Ordering posts by custom field named “date” in backend
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- Convert all dates stored in custom field
- How show post only from after custom date
- How to query posts by month based on date custom field?
- Order by custom date field
- Group Posts By Custom Meta Value: Date
- WordPress Admin – Automatically Sort Custom Posts by Custom Field Date Value in d-m-Y Fomat
- Thirtieth century date for a post
- Order a query by meta_value and then by post_date
- Complex WP_Query Using Post Date And Post Meta
- Checking if field is set before comparing with meta_query in query_posts?
- Display posts where date field matches current month?
- Dynamically update Custom Fields to display new dates
- Archive for custom fields?
- Meta Query with AND & OR?
- Problem with serialized arrays in custom meta
- Adding another state (spam, reject, approve) to wordpress comments?
- WP doesn’t show Array Custom Fields?
- How do I search an array stored in a custom-field using WP_Query?
- Custom text-only header
- How to save custom fields for attachments
- How to get a meta value from all post
- Adding existing user custom field value to a woocommerce product [closed]
- How to save values of a custom input field on the Network > Site Info screen
- Exclude custom post type from search by custom field value?
- Adding Custom Text Area to WooCommerce Product
- Get multiple custom field values in a $wpdb query [duplicate]
- add meta box using function.php
- converting custom field date format
- How do I exclude posts by custom field value?
- Buddypress Add unserialized Profile Fields in Members Loop [closed]
- Add Paypal Button programmatically
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- Eliminating the appearance of a specific custom field in a post
- Conditional custom field query
- Conditionally hide or show woocommerce product variation in fontend by custom field
- custom meta box text field: how to limit to alpha or numeric only
- Guest Author – How to display posts on /author/ archive page
- Accessing loop functions (e.g the_title or the_content) from post ID
- Create an Array of Specific Custom Post Meta
- custom avatar removal
- Excluding Specific Fields from Profile Builder Registration Form
- Send email with custom fields after new draft is saved or new post published
- How to add upload video option in wordpress for user?
- Set post to unpublished after one week depending on condition
- URL Rewrite fires when retrieving a custom value?
- Efficiently sort only certain categories by custom field
- How can I do a variable for meta_query?
- How to list Category list in ACF Pro’s Select Field to choose from [closed]
- Singleton Custom Field (Meta Box)
- Display custom field & value correctly on page
- Displaying custom filed content instead of post content
- Copy price categories to custom field
- Save all the post tags inside a custom field
- Use Advanced Custom Fields – replace line of code that hardcodes the tag into the template
- How to update a custom field in all posts with the value of another custom field in the same post?
- Advanced Custom Fields and Post Meta Fields Relation
- Set featured image from custom field URL
- Best Way to get facebook share count and update using wp_schedule_event or any other method
- Filter posts by custom field (Advanced Custom Fields)
- KEY and VALUE custom field issue
- Trying to implement AJAX into my admin pages. Am I improperly enqueue and localizing my scripts?
- WP E-Commerce Custom Meta > Serialized array
- Display Additional Info
- How do I upload file through custom field, save it to database and get it
- Custom meta fields and meta keys
- HTML for adding a meta box (basic text field) to page editor?
- Save Taxonomy of Post via custom Taxonomy Select Dropdown
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- use custom field value as featured image
- adding autosave feature to custom fields
- (woocommerce) How to get product id form order id & then retrieve custom meta linked to product?
- How to delete WooCommerce Products than have a specific custom field?
- Is it possible to manage Multiple Custom Fields with Some Relations
- How do I display posts ordered by a date custom field?
- Custom Metabox Always shows box and checked
- Create custom query for search?
- update_user_meta(): invisible data storage
- Updating custom fields with external data
- How to disable ‘enclosure’ custom field link from appearing in the post
- Help sorting by Meta Key value
- Custom classes for attachments
- Pagination not displaying correct number of pages
- Show div based on custom meta value
- Assign class to Drop Down Selections in WooCommerce Products Custom Fields
- Show/Hide Featured Image or replace it with custom field [closed]
- Change Post status based on custom field date +1 day