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