Skip to content

Instantly share code, notes, and snippets.

@Tom-Alexander
Created February 17, 2016 00:58
Show Gist options
  • Save Tom-Alexander/173511bbc7b1a763d9f5 to your computer and use it in GitHub Desktop.
Save Tom-Alexander/173511bbc7b1a763d9f5 to your computer and use it in GitHub Desktop.
silverstripe blog suggested posts
BlogPost::get()
->filter(['ParentID' => $this->owner->ParentID])
->leftJoin('BlogPost_Categories', 'BlogPost.ID = BlogPost_Categories.BlogPostID')
->where(
'BlogCategoryID IN (
SELECT BlogCategoryID FROM "BlogPost"
LEFT JOIN BlogPost_Categories ON BlogPost.ID = BlogPost_Categories.BlogPostID
WHERE BlogPost.ID = ' . $this->owner->ID . ')')
->exclude(['ID' => $this->owner->ID])
->sort('RAND()')
->limit($length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment