Home › Forums › ACF PRO › Getting number of times selected from relationship field › Reply To: Getting number of times selected from relationship field
Try $vars["orderby"] = "meta_value_num";
having both may be confusing WP.
Yes, what you’re doing will work, it just means that the value will be updated during the loading of the admin page and will not be updated at any other time. Only the posts you are currently viewing will be updated, so, only the first 20 posts. Once you have more than 20 posts you need to page through all of the lists until you’ve seen them all to get them all updated so that you filter will work. In addition to this you’re doing a WP_Query with a “LIKE” meta_query for every post listed. This could slow down your page loads considerably.
Using the acf/update_value hook will only do the updates when it needs to be done and all the values will be correct before you view the list on the admin page so that the filter will work correctly. You also remove the need to do the query for every post so the page will load faster.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.