Excluding a Tag from a posts query

edited February 2014 in Modules
I'm still running the 9.3 version of fuel. Inside this class:
class Fuel_posts extends Fuel_advanced_module {

I have:
function recent($limit = 5, $where = array())
{
$posts = $this->posts($where, 'post_date desc', $limit);
return $posts;
}

How would I create a similar method that excluded a certain tag from the list of posts returned?

I have another method that grabs all the posts for a particular tag, but it seems excluding just one tag isn't quite as straightforward. Can someone point me in the right direction.

Comments

  • edited 2:56PM
    Hmm... version .9.3 doesn't have a Fuel_advanced_module class. It's only 1.0 that has it.

    Are you looking for something like a where condition with the following:
    $where['fuel_tags.slug !='] =$tag;
  • edited 2:56PM
    Yes, that's the where clause I need. However, that gives me:

    Unknown column 'fuel_tags.slug' in 'where clause'

    So I'd need to join in the fuel_tags table right? I'm not seeing how to do this.
  • edited 2:56PM
    I figured it out. Not sure if this is the easiest way. But wanted to share my solution with others:

    $this->CI->load->module_model(POSTS_FOLDER, 'posts_model'); $this->CI->posts_model->readonly = TRUE; $this->CI->posts_model->db()->join('fuel_relationships', 'fuel_posts.id = fuel_relationships.candidate_key', 'INNER'); $this->CI->posts_model->db()->join('fuel_tags', 'fuel_relationships.foreign_key = fuel_tags.id', 'INNER'); $where['fuel_tags.slug !='] = $tag; $posts = $this->CI->posts_model->find_all($where, 'post_date desc', $limit, NULL, NULL, NULL); return $posts;
Sign In or Register to comment.