url/httpUrl in bootstrapped file

Recommended Posts

I included the PW index.php in a script file and need to return a full URL of pages (autocomplete Ajax response)

However, the file is located on another host and I get the wrong URL

I am wondering why ->url and ->httpUrl is /public/found/page/ or instead of /found/page/ or … and how to get the proper URL. Do I need to set the $config->httpHost again or something else?

<?php namespace ProcessWire; 
header('Access-Control-Allow-Origin: *'); 
include '../../../www/index.php';

$q = wire('sanitizer')->selectorValue( wire('input')->get('q') );
$results =  wire('pages')->find('title%=' . $q . ', template=basic-page, limit=10');

$array['query'] = $q;
foreach ($results as $result) {
	$array['suggestions'][] = ['value' => $result->title, 'data' => $result->url];

echo json_encode($array);


Share this post

Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.