Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function RelatedPosts($post)
- {
- $id = $post->id;
- $title = $post->post_title;
- $type = $post->post_type;
- $tags = get_the_tags($id);
- $queryTags = array();
- $postIDArray = array();
- if(is_array($tags)){
- foreach($tags as $tag)
- {
- //Comment out to exclude tags
- array_push($queryTags,strtolower($tag->slug));
- }
- }
- else{
- $titleArray = explode(" ", $title);
- foreach($titleArray as $tag)
- {
- //Comment out to exclude title
- array_push($queryTags,strtolower($tag));
- }
- }
- $filterArray = array(
- "of",
- "and",
- "is",
- "its",
- "a",
- "the",
- "am",
- "are",
- "as",
- "we",
- "be",
- "for",
- "you",
- "in",
- "than",
- "to",
- "me",
- "this",
- "that",
- "it"
- );
- foreach($queryTags as $tag)
- {
- foreach($filterArray as $filter)
- {
- if($tag==$filter)
- {
- $index = array_search($filter,$queryTags);
- if($index !== FALSE){
- unset($queryTags[$index]);
- }
- }
- }
- }
- $queryTagCSV = implode(",", $queryTags);
- if(!$tags)
- {
- $query = new WP_Query(array(
- 'post_type' => $type,
- 'posts_per_page' => '3',
- 'no_found_rows' => 1,
- 'orderby' => 'rand'
- ));
- }
- else
- {
- $query = new WP_Query(array(
- 'post_type' => $type,
- 'posts_per_page' => '3',
- 'no_found_rows' => 1,
- 'orderby' => 'rand',
- 'tag' => $queryTagCSV
- ));
- }
- return $query;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement