2

I have articles related to products (set up with Playa), and then some articles are not related to any product.

Is there a way to get all the articles where the Playa-field is empty?

4
  • 1
    Have you tried a custom query to get the entry ids that have no related entries in exp_playa_relationships? Commented Aug 22, 2014 at 5:20
  • @AndrisSevcenko No, I'm not that good with custom queries. Could you maybe help me get started with a custom query that would get those entries?
    – peirix
    Commented Aug 22, 2014 at 8:49
  • When you say "get", how do you mean? For use in your templates? Or a list in the control panel? Or just a one-time list of IDs/titles so you can perform some operation on those entries? Commented Aug 25, 2014 at 15:16
  • I have a separate page on my site where I want to list all the articles not related to any product. So I guess a list of entry-ids would be fine, because I can plug those directly into {exp:channel:entries}, right?
    – peirix
    Commented Aug 25, 2014 at 15:20

1 Answer 1

1
+50

Since you need some help with a query, I wrote this. You will need to change the part where channel = 4, and enable php on input for this template. I think this might work for you.

EDIT: You can just use the not in the entry id parameter

<?php

    // First we get the entries that are a playa parent
    $dontIncludeArray = array();

    $dontIncludeQuery = ee()->db->select('parent_entry_id')
                        ->from('playa_relationships')
                        ->get();

    foreach ( $dontIncludeQuery->result_array() as $row )
    {

        $dontIncludeArray[] = $row['parent_entry_id'];  

    }

    $dontInclude = implode('|' , $dontIncludeArray);
    ?>
 {exp:channel:entries channel="foo" entry_id="not <?php echo $dontInclude; ?>"}
        {title}<br>
    {/exp:channel:entries}
3
  • Woah! Thanks! It looks like it's really close, but it's getting all the articles. I've tried to set the where_not_in to take the $dontIncludeArray as the second parameter, as someone suggested that it should take an array and not a string, but that didn't help either. I've also tried echoing out $dontInclude, and it does contains an entry_id which shouldn't be outputted, so that query works fine.
    – peirix
    Commented Aug 25, 2014 at 19:32
  • I have edited my post, but you have enabled php on input right? This will not work on output Commented Aug 25, 2014 at 19:40
  • PS! "You may award your bounty in 19 hours.", so you'll have to wait for the bounty (:
    – peirix
    Commented Aug 25, 2014 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.