Sort related posts by category
-
Hi,
I really like this plugin, but I am a bit stuck in how to get the wanted output. Perhaps someone can direct me in the right direction.
In my website I have several custom post types that all together need to be grouped by another custom post type (called for example: Group). The posts linked to a Group have a category. Now on each single-post page I need to show a sort of index of what items are grouped in this Group and with which the visitor can navigate through the items in this group:
Group 1
Category A
* item 1
* item 2Category B
* item 3Category C
* item 4
* item 5I have registered a multi-connection in my functions as:
function my_connection_types() { $post_types = array( 'group', 'cpt-1', 'cpt-2','cpt-3','cpt-4' ); p2p_register_connection_type( array( 'name' => 'multi_connections', 'from' => $post_types, 'to' => $post_types, ) ); } add_action( 'p2p_init', 'my_connection_types' );And I manage to output the connected posts by:
<?php $related = p2p_type( 'multi_connections' )->get_related( get_queried_object() );?>However, I can’t seem to sort the posts by category as the desired way described above. Perhaps someone can point me in the right direction?
Thanks a lot!
The topic ‘Sort related posts by category’ is closed to new replies.