Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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 :-)

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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