filter pages *having* an attribute set (to anything)

Permalink 1 user found helpful
Hi,

digging in the forum, I found a lot of examples of how to filter a pagelist by attribute *value*, ($list->filterByCamelCasedHandle('value')) but I am after something ridiculously simplier (or just uncovered).

I added a complex attribute type that can not be (easilly) searched, and I would like to filter a pagelist to recover only pages having that attribute (to any value).

Is there anything I could use ? or will I have to hack some SQL ?

 
mnakalay replied on at Permalink Reply
mnakalay
How about just:
$myAttribute = $c->getAttribute('attribute_name');
if ($myAttribute ) {
    ...
}


It should work (with a for each loop of course)
goutnet replied on at Permalink Best Answer Reply
Well, the point is doing it in a PageList ...

Anyway, after quite some time digging in the c5 core code, here is the solution :

1. make sure your custom attribute search index is null by default
2. use $list->filterByAttribute( 'your_search_field', null, 'is not' )

if you have a custom attribute having multiple fields :

$list->filterByAttribute( array( 'your_field' => 'your_at_handle' ), null, 'is not' );

and tada !