1


Do you know why WordPress delete variables when I'm on a page of "custom post types" (singular) and not when I'm on a standard page?

Here is how I create my URL in a loop.

<a href="<?php echo esc_url( add_query_arg( 'p', $url, the_permalink() ) ); ?>">See more</a>

The link is generated correctly, but when I click "?p=value" is deleted...

Thanks in advance! :)

meneldil
  • 45
  • 8

1 Answers1

3

Issue is that you're using "the_permalink()" which outputs the value itself.

You need to use get_the_permalink() function.

Your new code will look like this:

<a href="<?php echo esc_url( add_query_arg( 'a', $url, get_the_permalink() ) ); ?>">See more</a>

Update:

Plus, you're trying to retain ?p=xxx in your url. WordPress takes p as a post id variable, and thus it uses it and uses permalink rewrite rules to redirect and remove this from the url.

You will retain the query variable if you use anything other than ?p= , try ?a=something e.g.

Nabeel Khan
  • 3,715
  • 2
  • 24
  • 37
  • Unfortunately this does not solve my problem. (but it is getting better, so thank you) For information, if I manually added "?p=value" in the url bar, this part is automatically deleted. – meneldil Apr 26 '16 at 09:26
  • can you share the link? – Nabeel Khan Apr 26 '16 at 09:31
  • this is because "p" is used by wordpress to show the post, it will retain any other variable, try ?a=something – Nabeel Khan Apr 26 '16 at 09:36
  • you're welcome :) I've added this to the answer too. please mark the ans as correct and also upvote if it was useful :) – Nabeel Khan Apr 26 '16 at 09:38