Jump to content
PCuser

Solved - Get URL of page by targeting template and multiple selection checkbox

Recommended Posts

I have the template: categories-template.php

And the select multiple choice checkbox field:
 categoryoptions
1 - red
2 - blue
3 - green

And 3 pages (using the template categories-template.php)

redpage (with the page id 1120 & the checkbox 'red' checked off on the field categoriesoptions)
bluepage (with the page id 1130 &  the checkbox 'blue' checked off on the field categoriesoptions)
greenpage (with the page id 1140 & the checkbox 'green' checked off on the field categoriesoptions)

When I try to target the blue page with:

<?php echo $pages->find("template=categories-template, artcategories=2"); ?>

I receive the right page ID, in the above example it outputs the id '1130'.

But

<?php echo $pages->find("template=categories-template, artcategories=2")->url; ?>

Doesn't get the page URL of bluepage, it just returns the URL of the current page that it is on.

Any suggestions? I've been troubleshooting this longer than I'd like to admit lol. Thanks

Share this post


Link to post
Share on other sites

$pages->find() returns a PageArray, and you can't get the URL of a PageArray. I think you want $pages->get() or $pages->findOne().

I recommend checking that a real page is returned before trying to get its URL.

$p = $pages->findOne("template=categories-template, artcategories=2");
if($p->id) {
   // Page was found, output its URL, etc
} else {
   // No page found, so deal with this somehow 
}

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you! findOne worked, I had tried get() instead of find() but it didn't work out.

And oops messed up my code example I gave by leaving wrong field name  (artcategories should be categoryoptions)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...