2

Can I pass numbers as parameters in URL? I am trying to get the slug name as below,

$slug = $post->post_name;
$pagePath = site_url() . '/listing-details/?p=' . $slug;

and trying to get the slug as below,

$the_slug = $_GET['p'];

Now the issue here, in some cases I am getting the $slug value as something like

650-jefferson-ave

Thus finally my URL which I am getting, becomes:

http://localhost/project/listing-details/?p=650-jefferson-ave

Thus in that case my $the_$slug is returning null and this url is redirecting the default http://localhost/project/listing-details/ page without any parameters.

How can I achieve this? Please anyone help.

4
  • 1
    You cant have another $ in the variable name Commented Feb 28, 2018 at 8:43
  • @MarvinFischer That was a typo. Corrected now. Commented Feb 28, 2018 at 8:55
  • 2
    It looks like it's got the article/page ID prepended to it. You need to split it off, using explode list($id, $slug) = explode('-', $_GET['p'], 2); Commented Feb 28, 2018 at 8:58
  • @Geoffrey Actually my post name contains names starting with digits. Commented Feb 28, 2018 at 9:37

1 Answer 1

1
$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['email'];

and make sure you have a parameter p after your url

like

/post/?p=something
Sign up to request clarification or add additional context in comments.

2 Comments

I am already doing this. The issue here is /post/?p=$slug is having numbers thus it is returning nothing.
This isn't working. Can u please have a look on the edited question? Maybe you can get an idea on what I mean.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.