WordPress: How to sort content by ACF custom field?

╄→гoц情女王★ 提交于 2019-12-05 15:41:23

You are almost there

If you change the choices in the Advanced Custom Fields to

1 : Free
2 : Business
3 : Commercial
4 : Professional
5 : Ultimate
6 : Ultimate Plus

And then the default to 1

By doing this you are setting the values to the number and the default is the Free value. In the admin screen you will be presented with the text value.

Then to do your query try this for the query

$wp_query = get_posts(array(
  'numberposts' => -1,
  'post_type' => 'directory_listings',
  'meta_key' => 'membership_type',
  'orderby' => 'meta_value',
));

It will get all of the posts that have a value set and order it by the membership type descending which is what you want.

I have tried this on my local setup to confirm this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!