Revisions
- October 18, 2013 @ 00:15:37 [Current Revision] by PeterLugg
- October 18, 2013 @ 00:15:37 by PeterLugg
- July 2, 2013 @ 12:12:26 by PeterLugg
- July 2, 2013 @ 12:11:19 by PeterLugg
Revision Differences
July 2, 2013 @ 12:12:26 | Current Revision | ||
---|---|---|---|
Content | |||
Unchanged: [php] | Unchanged: [php] | ||
Deleted: <pre>< code><?php | Added: <?php | ||
Unchanged: $term = get_term_by( 'slug', get_query_var( 'tag' ), "post_tag" ); | Unchanged: $term = get_term_by( 'slug', get_query_var( 'tag' ), "post_tag" ); | ||
Unchanged: $tagslug = $term->slug; | Unchanged: $tagslug = $term->slug; | ||
Unchanged: $post_types = get_post_types( '','names'); | Unchanged: $post_types = get_post_types( '','names'); | ||
Unchanged: ?> | Unchanged: ?> | ||
Unchanged: <?php | Unchanged: <?php | ||
Unchanged: //first query | Unchanged: //first query | ||
Unchanged: $blogposts = get_posts(array( | Unchanged: $blogposts = get_posts(array( | ||
Unchanged: 'tag' => $tagslug, //first taxonomy | Unchanged: 'tag' => $tagslug, //first taxonomy | ||
Unchanged: 'post_type' => $post_types, | Unchanged: 'post_type' => $post_types, | ||
Unchanged: 'post_status' => 'publish', | Unchanged: 'post_status' => 'publish', | ||
Unchanged: )); | Unchanged: )); | ||
Unchanged: //second query | Unchanged: //second query | ||
Unchanged: $authorposts = get_posts(array( | Unchanged: $authorposts = get_posts(array( | ||
Unchanged: 'bookauthor' => $tagslug, //second taxonomy | Unchanged: 'bookauthor' => $tagslug, //second taxonomy | ||
Unchanged: 'post_type' => $post_types, | Unchanged: 'post_type' => $post_types, | ||
Unchanged: 'post_status' => 'publish', | Unchanged: 'post_status' => 'publish', | ||
Unchanged: )); | Unchanged: )); | ||
Unchanged: $mergedposts = array_merge( $blogposts, $authorposts ); //combine queries | Unchanged: $mergedposts = array_merge( $blogposts, $authorposts ); //combine queries | ||
Unchanged: $postids = array(); | Unchanged: $postids = array(); | ||
Unchanged: foreach( $mergedposts as $item ) { | Unchanged: foreach( $mergedposts as $item ) { | ||
Unchanged: $postids[]=$item->ID; //create a new query only of the post ids | Unchanged: $postids[]=$item->ID; //create a new query only of the post ids | ||
Unchanged: } | Unchanged: } | ||
Unchanged: $uniqueposts = array_unique($postids); //remove duplicate post ids | Unchanged: $uniqueposts = array_unique($postids); //remove duplicate post ids | ||
Unchanged: $posts = get_posts(array( | Unchanged: $posts = get_posts(array( | ||
Unchanged: 'post__in' => $uniqueposts, //new query of only the unique post ids on the merged queries from above | Unchanged: 'post__in' => $uniqueposts, //new query of only the unique post ids on the merged queries from above | ||
Unchanged: 'post_type' => $post_types, | Unchanged: 'post_type' => $post_types, | ||
Unchanged: 'post_status' => 'publish', | Unchanged: 'post_status' => 'publish', | ||
Unchanged: )); | Unchanged: )); | ||
Unchanged: foreach( $posts as $post ) : | Unchanged: foreach( $posts as $post ) : | ||
Unchanged: setup_postdata($post); | Unchanged: setup_postdata($post); | ||
Deleted: ?></code> </pre> | Added: ?> | ||
Unchanged: [/php] | Unchanged: [/php] |
Note: Spaces may be added to comparison text to allow better line wrapping.
No comments yet.