admin管理员组文章数量:1415111
I am creating a theme for a classifieds website and want to list the top 8 popular city which mentioned as posts custom fields. That means the top 8 cities which have the most classifieds. It will looks like this:
I saw some examples of sorting custom fields but couldn't manage to make them work properly.
I am creating a theme for a classifieds website and want to list the top 8 popular city which mentioned as posts custom fields. That means the top 8 cities which have the most classifieds. It will looks like this:
I saw some examples of sorting custom fields but couldn't manage to make them work properly.
Share Improve this question edited Aug 26, 2019 at 8:51 Jan Doggen 16911 bronze badges asked Nov 17, 2012 at 19:31 Emre CaglarEmre Caglar 511 gold badge1 silver badge4 bronze badges1 Answer
Reset to default 1Let 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.
本文标签: sortListing the most popular 8 city (custom fields) as used in posts
版权声明:本文标题:sort - Listing the most popular 8 city (custom fields) as used in posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745214348a2648073.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论