Jump to content

wire('pages')->get(id) not working?


formmailer
 Share

Recommended Posts

Hi,

I am trying to find the url of some pages, I have the page ID so I figured that something like this should work.

$linkurl = wire('pages')->get(1187)->url
... do something ...
$linkurl = wire('pages')->get(1186)->url
... do something ...
$linkurl = wire('pages')->get(1093)->url
... do something ...
$linkurl = wire('pages')->get(1097)->url
... do something ...

But whatever I try I get the root url as $linkurl.

I even tried it with ->title, just to see what happened. Every time I got the title of the homepage.

Am I doing something wrong or is wire('pages')->get(id) not working?

I use the latest commit.

//Jasper

Link to comment
Share on other sites

I meant, replacing

wire('pages')->get(1187)->url

for

$wire->pages->get(1187)->url

But I thought you where bootstrapping PW by including the index file.

In this case, maybe you can add some parameters to the function, and put those calls there.

Link to comment
Share on other sites

I am doing something wrong. :(

This is the exact code I am using:

 if($child->link_intern_url) {
 $linkid = $child->link_intern_url;
 $linkurl = wire('pages')->get($linkid)->url;}

When I enter an ID manually, instead of the $linkid variable it is working.

The field link_intern_url is a page reference field.

/Jasper

Link to comment
Share on other sites

Figured it out... As usual it's my mistake... :rolleyes:

When using a variable, I need to use quotes. :-[

  if($child->link_intern_url) {
 $linkurl = wire('pages')->get("$child->link_intern_url")->url;}

/Jasper

Link to comment
Share on other sites

What is "$child->link_intern_url"?

if it's a page from a page reference it should reuturn the page object. so you should be able to do:

$url = $child->link_intern_url->url;
  • Like 1
Link to comment
Share on other sites

if it's a page from a page reference it should reuturn the page object. so you should be able to do:

$url = $child->link_intern_url->url;

Duh... why is ProcessWire so easy... I am always trying to do things the complicated way. :lol:

Thanks!

/Jasper

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

×
×
  • Create New...