0

I am trying to redirect to another URL using this code--

 $siteurl= get_site_url();
//echo " This is basic property search.... now redirecting";
//echo "\n\n Redirect URL for property posts=" + $redirecturl;
wp_redirect( "http://" . $siteurl . "?post_type=property&search_keyword=" + $search_keyword
. "&submit=Search" . "&price-min=" . $price_min . "&price-max=" . $price_max
. "&city=" . $address_city . "&state=" . $address_state
. "&zip=" . $address_zip . "&beds=" . $beds . "&baths=" . $baths);

But this is where the redirection is happening--

http://dimitri.clientdemos.pw/105&submit=Search&price-min=&price-max=&city=&state=&zip=&beds=&baths=

What am I doing wrong here? Why is the correct URL not being used for redirection?

1 Answer 1

2

You're using a + sign for the first instance of string concatenation. Using a . instead should fix it.

Additionally, WordPress provides some useful functions that might make this code easier:

wp_redirect(
    add_query_arg(
        array(
            'post_type'      => 'property',
            'search_keyword' => $search_keyword,
            'submit'         => 'Search',
            'price-min'      => $price_min,
            'price-max'      => $price_max,
            'city'           => $address_city,
            'state'          => $address_state,
            'zip'            => $address_zip,
            'beds'           => $beds,
            'baths'          => $baths,
        ),
        site_url()
    )
);

add_query_arg() allows you to build a URL with new query arguments, instead of using messy string concatenation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.