Skip to content
Browse files

first pass at infering direction using 'post_type' query var. fixes #94

  • Loading branch information...
1 parent a37bb51 commit d46cb55cae8b45c3580c53d4a9d824b65cdd3fdd @scribu scribu committed Jan 15, 2012
Showing with 38 additions and 1 deletion.
  1. +38 −1 core/query-post.php
View
39 core/query-post.php
@@ -19,7 +19,10 @@ function parse_query( $wp_query ) {
if ( !isset( $q['connected_items'] ) )
return;
- $r = P2P_Query::expand_connected_type( $q, 'post' );
+ if ( !isset( $q['connected_type'] ) )
+ return;
+
+ $r = self::expand_connected_type( $q, 'post' );
if ( false === $r ) {
$q = array( 'year' => 2525 );
@@ -29,6 +32,40 @@ function parse_query( $wp_query ) {
}
}
+ // null means do nothing
+ // false means trigger 404
+ // true means found valid p2p query vars
+ function expand_connected_type( &$q, $object_type ) {
+ if ( !isset( $q['connected_type'] ) )
+ return;
+
+ $ctype = p2p_type( _p2p_pluck( $q, 'connected_type' ) );
+
+ if ( !$ctype )
+ return false;
+
+ if ( isset( $q['connected_direction'] ) ) {
+ $directed = $ctype->set_direction( _p2p_pluck( $q, 'connected_direction' ) );
+ } else {
+ if ( 'any' == $q['connected_items'] ) {
+ $post_type = isset( $q['post_type'] ) ? $q['post_type'] : 'post';
+ } else {
+ $post_type = $q['connected_items'];
+ }
+
+ $directed = $ctype->find_direction( $post_type, true, $object_type );
+ }
+
+ if ( !$directed ) {
+ trigger_error( "Can't determine direction", E_USER_WARNING );
+ return false;
+ }
+
+ $q = $directed->get_connected_args( $q );
+
+ return true;
+ }
+
function posts_clauses( $clauses, $wp_query ) {
global $wpdb;

0 comments on commit d46cb55

Please sign in to comment.
Something went wrong with that request. Please try again.