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
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
- WP_Query – Order results by meta value
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- getting all values for a custom field key (cross-post)
- How to add a custom field in the advanced menu properties?
- Custom query with orderby meta_value of custom field
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- Using meta query (‘meta_query’) with a search query (‘s’)
- Can I exclude a post by meta key using pre_get_posts function?
- Add validation and error handling when saving custom fields?
- Show Custom Fields in Quick Edit
- Where are custom field values stored in the database
- Validating Custom Meta Box Values & Required Fields
- Max length of meta_value
- How do I set the default admin sort order for a custom post type to a custom column?
- Add custom fields to wp native gallery settings
- How to fix missing custom fields after upgrading to WordPress 4.8.1?
- How to enable custom fields for pages (if not a bad practice)?
- How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
- Is there a way to set default custom fields when creating a post?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Custom field/meta populated by dropdown of existing posts?
- Difference between meta keys with _ and without _ [duplicate]
- Is there any action filter/hook for validating a custom field before publishing the post?
- Remove Dimension from wp_get_attachment_image
- Underscores in custom fields
- What is the index [0] for on post meta fields?
- Using meta_query, how can i filter by a custom field and order by another one?
- What is “meta_input” parameter in wp_insert_post() used for?
- Query Posts or Get Posts by custom fields, possible?
- How to enable revisions for post meta data?
- Sortable Custom Columns in User Panel (users.php)?
- Any way to add custom options to Gallery Settings?
- The “_encloseme” Meta-Key Conundrum
- Individual Widgets per Page
- Add subtitle to Woocommerce product title
- Best way to programmatically remove a category/term from a post
- Importing data for advanced custom fields plugin?
- Gutenberg add a custom metabox to default blocks
- SQL Query to copy value of a meta_key into another meta_key
- ‘Preview Changes’ for custom meta boxes?
- Adding a custom field to the site identity menu
- Using TinyMce with textareas in meta boxes on custom post types
- Filter WP_Query for posts having a certain meta-value
- How to correctly call custom field dates into a posts_where filter using SQL statements
- Using get_post_meta with new_to_publish
- Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
- Add a Jquery Datepicker to custom field in post edit
- add meta box – custom field : which to choose?
- Preserving line breaks when saving and displaying custom fields data
- How to return Meta data from the REST API?
- Advanced Custom Fields – Get custom fields from parent page
- Can I query custom meta data through WP_Query
- Add custom field to the archive page?
- Saving custom data for each user
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- Tabindex on text input immediately after WordPress title input
- Including custom fields in search?
- Add custom fields to search