Open fl0ri opened 6 years ago
Hello, I have the same issue. Have you discovered a way to query for posts based on the number of connections? This would be most useful for querying for user to posts connections to determine the most popular posts.
No, unfortunately not. I couldn't find a way to query the count of relations/connections.
OK, thanks for the reply. I figured their probably isn't a way to do this. So I built a workaround, I created a meta field in functions.php called 'p2p_post_counter' and then wrote a small plugin with functions that increment and decrement that field every time a connection is made.
I only need this data for user to post connections, so in my case I added code to the plugin Restful P2P which is primarily for that type of connection. Now when a connection is made or a connection is deleted it calls the function that updates the counter. https://thestizmedia.com/create-posts-2-posts-connections-wordpress-rest-api/
I could elaborate more if anyone is interested but the concept is pretty simple. The only drawback is it's not retroactive so to speak, so prior connections obviously won't be counted.
Wow. That’s neat. Thanks for posting.
I have two cpts "partner" and "event". Now I want to list all "partners" according to the number of connections they have to "events". How do I query the connections to get the count? PS: Plus it would be awesome to display the actual count of connections alongside the cpt (in brackets).