All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Searching for entries which are children of a Playa field within a Matrix

Derek 13 May 2013 16:51 question, complete

I am developing a magazine site, and am searching for articles based on the issue they appeared in. Articles are grouped into issues via each Issue entry. It has a Matrix (issue_toc), which has a Playa column, and that Playa field selects an entry from Articles.

I had thought that maybe this would work, but its not doing the trick. (Simplified example - entry_id is the parent Issue's.)

<a href="{exp:low_search:url parent:issue_toc="{entry_id}" collection="articles"}">See all articles from {title}</a>

Am I on the right track? Is this even possible?

Replies

  1. Low 13 May 2013 17:04

    If you look at the exp_playa_relationships table, the parent:-param will give you all child_entry_ids where the parent_entry_id is the given ID. However, since you're using Matrix, the parent_entry_id will be NULL and the relationship is determined by parent_col_id and parent_row_id instead.

    So, alas, no. It's not possible at the moment...

  2. Derek 13 May 2013 17:17

    Gotcha, I figured as much. Will rework.

  3. Derek 13 May 2013 19:59

    Update: solved this for myself using the low_search_catch_search extension hook - others could repurpose this pretty easily to suit their particular setup.

    public function low_search_catch_search($data) 
    {
    if(!empty($data['article_issue']))
    {
    $articles = $this->EE->db->query("
    SELECT child_entry_id
    FROM exp_playa_relationships
    WHERE parent_entry_id = ".$this->EE->db->escape_str($data['article_issue'])."
    AND parent_col_id = 5
    AND parent_field_id = 22
    ");
    if($articles->num_rows() > 0)
    {
    $ids = array();
    foreach($articles->result_array() as $article)
    {
    $ids[] = $article['child_entry_id'];
    }
    $data['entry_id'] = implode('|', $ids);
    }
    }
    return $data;
    }