Jump to content

Recommended Posts

Posted

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

Posted

It's in a function, so $pages->get(1093)->url; doesn't work there.

But outside the function that's working.

/Jasper

Posted

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.

Posted

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

Posted

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

Posted

I just tried and it's working as expected. Whether inside or outside a function.

echo wire("pages")->get(1002)->url;
Posted

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
Posted

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

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...