Jump to content

Recommended Posts

Posted

Hello,

I have a fieldtype Page named 'category' in my pages. I want to find pages from several categories like this:

$teaser=$pages->find("template=video,category.id=17|19|23,sort=-created");

This works great. Now I try the same thing on "my own" pageArray:

$sql = "select distinct video from views order by created desc";
$result = wire('db')->query($sql);
$bw = new PageArray;
while($row = $result->fetch_array()) {
if($video = $pages->get($row['video'])->id) $bw->add($video);
}

$teaser=$bw->filter("template=video,category.id=17|19|23");

... now $teaser contains nothing. It works well when I leave out "category.id=[...]" in the filter ...

Can anyone help?

Thanks,

thomas

Posted

I'm a little confused as to what you're doing here :)

Why are you querying the db manually? Those fields and table are custom and video is the id of a page in PW?

Well does the db query return any result at all? Any errors?

What if you leave out the .id in category.id? Have you tried a fiend instead of a filter?

Posted

Hi Soma,

"views"is a simple table which writes a page id whenever someone watches a video on my site. I expect this to get rather large so I didn't want it to be PW pages. The query returns an array of page id's and works fine. As I said, everything works fine until I add "category.id" to filter (or "find", I tried both) ... I'll try leaving out the .id ...

Thanks,

thomas

Posted

Thanks again, I can't get it to work. Leaving the "id" will work a little better, but only with one id, not several id's divided by a pipe.

Posted

Subfields like "category.id" aren't currently supported by the PageArray in-memory find/filtering functions. Though I think I can add this easily enough. However, "category" should resolve to the id property anyway, so you probably don't need it.

Posted

Thanks for the info Ryan,

I now changed the code to this:

while($row = $result->fetch_array()) {
if($video = $pages->get("id=".$row['video'].",category.id=17|23|9")->id) $bw->add($video);
}

thus avoiding the problem. Not sure if this is better or worse in performance terms but at least it works ...

- thomas

Posted

This might be a more efficient way to go, by converting multiple $pages->get() calls into 1 $pages->find() call.

$ids = array();
while($row = $result->fetch_array()) $ids[] = $row['video']; 
$bw = $pages->find("id=" . implode('|', $ids) . ", category=17|23|9"); 
  • Like 1
Posted

Thanks for the tip Ryan! I just tried it but the problem is I need the original sort order from the "views" table.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...