Skip to content

Instantly share code, notes, and snippets.

@danielkmariam
Created September 5, 2013 15:55
Show Gist options
  • Save danielkmariam/6452110 to your computer and use it in GitHub Desktop.
Save danielkmariam/6452110 to your computer and use it in GitHub Desktop.
public function setPartialSelect($type='category', $postTag='post_tag')
{
$cataoryPosts = $this->getCatagoryPosts($type, $postTag);
echo get_class($catagoryPosts);
$tagPosts = $this->getTaggedPosts($type, $postTag);
$this->getSelect()->reset()->union(array(
$cataoryPosts,
$tagPosts
))->distinct();
return $this;
}
public function getCatagoryPosts($type, $postTag)
{
$tableTax = $this->getTable('wordpress/term_taxonomy');
$tableTermRel = $this->getTable('wordpress/term_relationship');
$tableTerms = $this->getTable('wordpress/term');
$select = Mage::getModel('wordpress_resource/post_collection')->getSelect()
->join(
array('rel_' . $type => $tableTermRel),
"`rel_{$type}`.`object_id`=`main_table`.`ID`", '')
->join(
array('tax_' . $type => $tableTax),
"`tax_{$type}`.`term_taxonomy_id`=`rel_{$type}`.`term_taxonomy_id`
AND `tax_{$type}`.`taxonomy`='{$type}'", '')
->join(
array('terms_' . $type => $tableTerms),
"`terms_{$type}`.`term_id` = `tax_{$type}`.`term_id`", '')
->where("`terms_{$type}`.`slug` NOT IN (?)", array('news', 'uncatagorised'))
->distinct();
return $select;
}
public function getTaggedPosts($type, $postTag)
{
$tableTax = $this->getTable('wordpress/term_taxonomy');
$tableTermRel = $this->getTable('wordpress/term_relationship');
$tableTerms = $this->getTable('wordpress/term');
$select = Mage::getModel('wordpress_resource/post_collection')->getSelect()
->join(
array('rel_' . $type => $tableTermRel),
"`rel_{$type}`.`object_id`=`main_table`.`ID`", '')
->join(
array('tax_' . $postTag => $tableTax),
"`tax_{$postTag}`.`term_taxonomy_id`=`rel_{$type}`.`term_taxonomy_id`
AND `tax_{$postTag}`.`taxonomy`='{$postTag}'", '')
->join(
array('terms_' . $postTag => $tableTerms),
"`terms_{$postTag}`.`term_id` = `tax_{$postTag}`.`term_id`", '')
->where("`terms_{$postTag}`.`slug` NOT IN (?)", array('hellooo'))
->distinct();
return $select;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment