Jump to content

Issue with finding page created via API


Mikie
 Share

Recommended Posts

Hi there!

I'm experiencing a weird problem creating pages via the api. My actual code is a bit more complicated, but the below summarises the issue.

Would explicitly setting the name when creating a page cause this problem in anyone's experience? I am doing this for a reason, as I am creating thousands of pages through the api and the page titles have all sorts of characters that break selectors in them. I was experiencing issues both sanitising the titles (titles wrapped in quotations) and searching with sanitised titles, I thought creating a sanitised name variable would help my logic for checking for page existence and let me leave the titles as they were.

$title = "Page Name";
$name = $sanitizer->pageName($title);
$parent = $pages->get("name=parent");

$p = new Page();
$p->template = "template";
$p->parent = $parent;
$p->title = $title;
$p->name = $name;
$p->save();

$test1 = $pages->get("name=$name,parent=$parent"); // NullPage
$test2 = $pages->get("title=$title,parent=$parent"); // correct Page object

 

Link to comment
Share on other sites

Page names have to be unique (if they share the same parent). If you create a new page with an already existing page-name, PW will append an integer. If you clone a page, it will add " (copy)" to the title, and also an auto-increment number to the page name. This happens both when you use the API or GUI. Maybe that's the problem here?

You could check with slightly altering the selector for page name: 

1 hour ago, Mikie said:

$test1 = $pages->get("name%=$name,parent=$parent"); // NullPage

name%= instead of name=

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