Let MySQL do the job:
global $wpdb;
$metakey = 'YOUR_METAKEY_GOES_HERE';
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT meta_value, COUNT(*) AS counter from {$wpdb->postmeta} WHERE meta_key = %s GROUP BY meta_value ORDER BY counter DESC", $metakey, ARRAY_N )
);
);
$resuls
is an array with the ordered results.
Related Posts:
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Orderby meta_value only returns posts that have existing meta_key
- ORDER BY custom field value
- Auto sort the wp-admin post list by a meta key
- get_pages sort alphabetically by meta value
- Archive sorting functions by custom fields (front-end)
- Order by custom field date?
- How can I sort get_users() by any value (last_name, user defined fields and more)
- Is it possible to order posts by two meta values?
- Sorting posts by multiple values, combined
- Sort by posts that have a featured image?
- sort search results by custom fields using dropdown
- Sorting posts ordered by custom field value
- Sorting WordPress Posts via Custom Field Values?
- Advanced search by two criteria – sort by location and date (ascending or descending)
- Change the sort order for posts to include custom field
- Sort custom post type by multiple custom fields
- Sort alphabetically by custom field
- Trying to sort and display categories(not posts) by custom field: ‘order’
- Sort WP_Query with numeric custom field
- ORDER BY custom field value out of where clause
- wordpress custom loop ascending descending posts by custom field
- Select custom posts by meta_value and sort by a different meta value
- change order of images attached to post
- Sort posts by clicks on download button
- How To Show Get Adjacent Posts If Posts Are Sorted By Custom Field
- How to sort by custom field value?
- Custom Query Fields – Altering Meta Value
- How to order posts by number of Vimeo Likes
- Filter or order based on custom field
- Compare ACF date field (if exists) and post date and order DESC
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Sort posts by custom fields with empty values
- Sort custom fields in admin by last field added
- list pages by custom_field?
- Sort posts after filtering them through multiple taxonomies
- Can’t sort custom column on user.php by number / meta_value_num?
- Order by a meta field in query loop
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- Add custom fields to search
- Sorting a query by custom field date
- How to get users by a custom field / by user meta data?
- extend Meta Box / Document Panel
- getEntityRecord without knowing the post type
- Add custom field to image editor
- TinyMCE in Custom Metabox not loaded after upgrading from WP 3.1.4 to WP 3.2
- ajax delete value from custom field array
- Custom field for default gallery
- After moving my site from a dev subdomain, to root, all my custom meta data is gone
- How can I query on the year part of a complete date in a custom field?
- Gravity Forms: Create fields programmatically
- WordPress Custom Field Should be Unique. Is it possible?
- all tincymce’s switch when updating page after changing from html to text in custom metabox
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How to display Meta Field Value?
- Add source URL from Feed WordPress (Syndication) plugin to a custom field in post editor
- List custom taxonomy terms from custom field
- How do I create a column in Users list and display user data from custom registration field
- Better Method for Multiple Meta Boxes
- Remove Body Classes
- Product Custom Fields with HTML and JS
- Add new image block, set default class name and update it using Javascript
- Add image to menu item with ACF
- Client PDF Upload (Catalogue) – Automatically update link to PDF
- Button inside Custom Meta Box triggering the Update Button
- How to load an assets based on custom field value?
- Adding auto-complete to custom gravity field not working
- Search in Archive Pages by subcategory, tag, custom field and year
- Get image url using image id
- Only show when content added via custom field
- Using a custom field inside a shortocde
- Add Custom Profile Field as Notes
- Woocommerce frontend edit custom fields
- Can’t Output get_post_meta?
- Add specific custom fields to post formats
- Displaying an ACF list of users
- Meta value Array
- get_post_meta returns 0
- Custom field bug in WordPress 3.2
- Users uploaded image and matching an id or taxonomy
- Let any visitors delete a post if they know Id nr & password?
- update a custom field with the value of another existing custom field
- Post meta data not showing in frontend, until hitting ‘update’ button
- Ordering posts by custom fields (Date)
- PHP and Shortcode Combination
- Retrieving Advanced Custom Field within Shortcode Function [closed]
- How to properly get popular Posts by multiple Values
- Get custom fields when hover link of post
- WP Query multiple select form – meta_query help
- update_post_meta not working in action hook
- Group pages by custom field values
- How to create Parent-Child relation for custom fields?
- How to check if custom field exists in this widget query
- display loop only if a post meta data exist
- How do i output images from URL’s added to the same custom field key
- Add Custom field under the post title [closed]
- Check if a field is capitalized?
- Need to call this php function inside a modal window from text widget
- Multiple triggers when publishing, saving or updating a post in WordPress
- If possible a field ID transfom in a Custom Field?