Jump to content


Photo

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

Solved

  • Please log in to reply
8 replies to this topic

#1 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 28

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 05 March 2012 - 05:15 AM

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

#2 diogo

diogo

    Hero Member

  • Moderators
  • 1,980 posts
  • 1060

  • LocationPorto, Portugal

Posted 05 March 2012 - 05:53 AM

Should work... did you try also with $wire->pages?

#3 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 28

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 05 March 2012 - 06:09 AM

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

/Jasper

#4 diogo

diogo

    Hero Member

  • Moderators
  • 1,980 posts
  • 1060

  • LocationPorto, Portugal

Posted 05 March 2012 - 06:19 AM

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.

#5 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 28

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 05 March 2012 - 06:37 AM

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

#6 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 28

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 05 March 2012 - 06:45 AM

Figured it out... As usual it's my mistake... ::)
When using a variable, I need to use quotes. :-[

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

/Jasper

#7 Soma

Soma

    Hero Member

  • Moderators
  • 3,184 posts
  • 1737

  • LocationSH, Switzerland

Posted 05 March 2012 - 06:48 AM

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

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

@somartist | modules created | support me, flattr my work flattr.com


#8 Soma

Soma

    Hero Member

  • Moderators
  • 3,184 posts
  • 1737

  • LocationSH, Switzerland

Posted 05 March 2012 - 06:51 AM

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;

@somartist | modules created | support me, flattr my work flattr.com


#9 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 28

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 05 March 2012 - 07:01 AM

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users