The following code allows you to add the parameters wpse4528_key
and wpse4528_minimum
to your queries, and will then add an extra criterium to the where clause that counts the number of meta values with your key.
add_filter( 'posts_where', 'wpse4528_posts_where', 10, 2 );
function wpse4528_posts_where( $where, &$wp_query )
{
global $wpdb;
$count_key = $wp_query->get( 'wpse4528_key' );
if( $count_key ) {
$where .= $wpdb->prepare( " AND (SELECT COUNT(*) FROM {$wpdb->postmeta} WHERE {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID AND {$wpdb->postmeta}.meta_key = %s) >= %d", $count_key, $wp_query->get( 'wpse4528_minimum' ) );
}
return $where;
}
Related Posts:
- Custom query with orderby meta_value of custom field
- Query Posts or Get Posts by custom fields, possible?
- query_posts and only show results if a custom field is not empty
- Filter archive.php by custom meta
- Order posts by custom field and if custom field is empty return remaining posts
- How to use query_posts() with a date filter on a custom field?
- meta_value_num sort glitch
- Can ordering post list by meta_value cause performance issue?
- Order by value in serialized custom field
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How do I query for a post by custom field?
- meta query not showing any results?
- how can i use custom field in query post
- using multiple meta_key and meta_value in query_posts
- Query post order by post and desc not working
- How can I sort homepage by a meta value?
- Order query by meta_value with multiple custom fields
- Show 1 post and after a specific date show the next one
- How to select posts from multiple categories and metavalues?
- meta_compare seems to be treating values as strings instead of integers as expected
- Change order of posts
- filter custom field values $min $max
- query posts custom field calculation value
- WP Query – Is this correct?
- Query_posts with custom field meta value
- Unable to get specific value from post meta
- Meta_query ‘compare’ => ‘LIKE’ not working?
- query_posts with meta_value
- Custom search SQL Query to add custom field in result
- How to put forward a blog post
- How can I change the publish date based on a custom field?
- Get author total post votes from post meta
- Problem with writting correctly a query posts args in WordPress
- simple fields plugin custom query
- query_posts -> get page_id from custom field
- Checking if field is set before comparing with meta_query in query_posts?
- Filtering posts by WORD in custom field
- Display agents (custom post type) alphabetically, except one who always shows last
- Filter Query Post by Custom Fields(by date)
- Underscores in custom fields
- Add custom field to the archive page?
- Need small coding with Custom Fields Search
- How can I remove fields in the attachment editor?
- Unable to get Preview of Uploaded image within a Custom Meta box
- How to store the value of a custom field dropdown select for post referencing?
- WordPress Search Custom Meta Field Only
- How can I migrate all of my custom field thumbnails to the built-in post featured image?
- Multiplile values checkbox or select in custom meta box
- Login & Register & Custom details WITHOUT plugin
- Escaping Quotes
- wp_editor removes paragraph from custom meta box
- Any way to include custom fields in WP_Query results?
- Ordering posts by date custom field
- Where did the Add New Custom Field go?
- Sorting WordPress Posts via Custom Field Values?
- Syntax highligting for custom fields
- Displaying a checkbox array from advanced custom field
- Display custom field values from posts on frontpage
- WordPress: custom field display twice
- Trying to sort and display categories(not posts) by custom field: ‘order’
- Show user info in a hovercard [closed]
- Shortcode To Display Post Custom Field Value in Post Title, Post Content
- edit_tag_form_fields is depricated but tag_edit_form_fields doesn’t work
- How to make a customized user registration form using the built in wp-register() template tag
- Link FROM attachment to full post and get custom fields values on attachment page?
- Getting the Featured image URL and inserting it as Custom Field on Post update / publish
- Adding custom field and querying from post table
- How to display a product features dynamically with icons?
- How to copy data from a custom field to the post_content?
- Custom field as featured image caption
- Update custom field values on edit address page woocommerce
- Is there a (sane) way to get all custom fields for a post, which do not have a leading underscore?
- custom filed from post in the side bar
- Rewrite comment form post ID on submit
- Move the metaboxes to the very top of post editor
- WordPress Rest API custom field not updating till i manually update the post
- Custom Fields not working properly
- add meta box considers the selected option as post parent
- Custom fields multiple commas separated values
- How do I display a custom field in an existing form on the front end?
- How to save array option as text and not integer?
- Delete custom meta
- Quicktag button to automatically add a custom field to a post
- Display custom fields only if it has a value
- Add nofollow to custom field link and make domain exceptions?
- wordpress simple post multi rating with post_meta and user_meta
- Custom fields are not displaying in page with multiple loops
- Add class from custom field into widget class
- Download stuff after filling fields?
- Get multiple posts with some custom fields efficient
- Adding custom field to Lightbox in header only pulls current page data, not Lightbox item data
- Meta boxes not displayed, data isn’t being saved
- Custom registration form and custom field
- Get single image from custom fields made with WCK custom fields creator
- How can i put a custom field inside this php
- Dynamically update Custom Fields to display new dates
- Display ACF object field data using Elementor Custom Query
- save all acf options in one meta_value [closed]
- Can running a WP-Cron to update_post_meta cause performance issues?
- custom field value is blank or empty