Home › Forums › General Issues › Order Posts by Most Popular Relational Post Object › Reply To: Order Posts by Most Popular Relational Post Object
This is not something that is directly possible and probably not easily done. You are trying to order posts based on information stored in 3 other fields that are not directly associated with the posts themselves. WordPress cannot be made to do this unless you want to write a lot of SQL queries and PHP code to get it done. In order to sort posts by something then that something needs to be information linked to the posts.
To do this properly you would not only need to keep a total of the times a post is selected you’d also need to keep a list of all the profiles where it is selected.
This is not a solution, just a rough idea of what you’ll need to do. You need to have 2 meta fields for each post. These fields do not need to be visible, they’ll just hold data. One field will be a total and the other field will keep a list of where it was selected in an array.
Then you need to set up an acf/save_post filter that will run when the user profile is updated. In this filter you look at each field and compare it to the current list. If a post is added or removed then you add/remove it from the list as well as update the total +/-. With this in place you can then sort the posts by this total field.
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.