0

Using Posts 2 Posts plugin I've created 'piece', 'person' and 'collection' custom post types: any piece may be connected to person (with roles 'author', 'conductor' etc) and collection.

Now the relevant code looks like this:

// get all audio pieces connected to current $person:
$audio_ascond = p2p_type( 'pieces_persons' )->get_connected( $person->ID,
      array( 'connected_meta' => array( 'role' => 'conductor' ),
         'media_tag' => 'audio_tag',
         'posts_per_page' => -1 ) );
// get their IDs:
$audio_ascond_IDs = array_map( create_function( '$p', 'return $p->ID;' ),
                                      $audio_ascond->posts );
// get collections for those pieces:
$colls = p2p_type( 'pieces_collections' )->get_connected( $audio_ascond_IDs,
            array( 'orderby' => 'menu_order title', 'posts_per_page' => -1 ) );

So, the problem is that 'orderby' has no any effect. Everything else works great. print_r($colls) looks like ok.

What this could be, please?

Thanks!

0

So, now I've decided to sort in php:

function compare_collections( $c1, $c2 ) { 
  if( $c1->menu_order == $c2->menu_order ) { 
    return ( $c1->post_title < $c2->post_title ) ? -1 : 1;
  } else {
    return ( $c1->menu_order < $c2->menu_order ) ? -1 : 1;
  }
}

// and then in my template:
uasort( $colls->posts, 'compare_collections' ) ;

But I would be glad to understand what's wrong :-)

My guess is that p2p_type( )->get_connected's sorting preferences are stronger or like that. Excuse me, I am not a programmer :-)

| improve this answer | |
  • Yes, it first orders by the connection field and then by whatever else you set. – scribu Nov 5 '11 at 11:03
  • @scribu Thank you. And a lot of thanks for your plugin!-) – brownian Nov 5 '11 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.