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.