Jump to content

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


PCuser
 Share

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

Link to comment
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
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...