Jump to content

$pages->find in config.php


cb2004
 Share

Recommended Posts

You'll need to do it with raw SQL. Something like this:

$pdo = new \PDO("mysql:host=$config->dbHost;dbname=$config->dbName", $config->dbUser, $config->dbPass);
$stmt = $pdo->query('SELECT `id` FROM pages WHERE templates_id = "29"');
$rows = $stmt->fetchAll(\PDO::FETCH_NUM);

 

  • Like 3
Link to comment
Share on other sites

6 hours ago, adrian said:

You'll need to do it with raw SQL. Something like this:


$pdo = new \PDO("mysql:host=$config->dbHost;dbname=$config->dbName", $config->dbUser, $config->dbPass);
$stmt = $pdo->query('SELECT `id` FROM pages WHERE templates_id = "29"');
$rows = $stmt->fetchAll(\PDO::FETCH_NUM);

 

Thanks so much for your reply Adrian. In the end I went with a solution in ready.php:

$members = wire('pages')->get(1302)->children;
$subMembers = array();
foreach($members as $m) $subMembers[] = $m->id;

And in config.php:

$config->usersPageIDs = array_merge($config->usersPageIDs, $subMembers);

Seems to be working ok, but what route would be best/fastest?

Link to comment
Share on other sites

@cb2004 - if that works, great - I didn't think it would work to set something in ready.php and use it in config.php

PS - you can simplify the $subMembers bit to:

$subMembers = wire('pages')->get(1302)->children->each('id');

or even better because it won't load the pages, just their IDs:

$subMembers = wire('pages')->findIDs('parent=1302');

 

  • Like 3
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...