admin管理员组

文章数量:1289529

I've been searching the internet for 6 hours now, so I decided to ask this in the forum and would appreciate every help.

I just want my permalink to say (e.g. portfolio, post, etc)

/?portfolio=xxxx&param=whatever

I need the param, because the post itself defines the "whatever" parameter and there is a search form in the post, which initializes itself using this parameter (the searchform gets the parameter, if it's in URL). For single links, I could've placed the param into the link, but the WP defines the permalinks restrictively.

I tried adding add_query_arg() to functions.php without success (It's not even clear where to place the code (single.php or functions.php) and how to call the function from the post).

I then tried adding custom fields and Meta Boxes, but they seem to conatin the extra parameter but not add it to the URL. So all I get is:

/?portfolio=xxxx

a.) BEST SOLUTION The best way would be, to add a custom field to the post (or post type), which inserts a value the param and shows the permalink-URL with that parameter.

b.) JUDO SOLUTION The simplest thing would be, to add this parameter (text) to the link.

There are a gazillion post about this online, but they all refer to parsing of parameters which external links pass ($_GET) and conditionally change the appearance of the site or adding one specific parameter/value to each post/page. I do not need this.

Is there any way to add this 1 single parameter to the permalink-URL directly from the post, without changing 18 php files and writing hundred lines of code?

Thank you for any help!

m

PS. I am using WP 3.6.1 DE with inovado

.

Things I have already tried


  1. WP Codex add_query_arg()
  2. Stackoverflow: question 4586835 how-to-pass-extra-variables-in-url-with-wordpress
  3. Cookie-monster: wordpress-url-parameter-utility
  4. Creativebloq: user-friendly-custom-fields-meta-boxes-wordpress-5113004
  5. Farinspace: how-to-create-custom-wordpress-meta-box
  6. stackexchange: questions 51444 - add-extra-parameters-after-permalink

and finally

  1. webopius: using-custom-url-parameters-in-wordpress

I've been searching the internet for 6 hours now, so I decided to ask this in the forum and would appreciate every help.

I just want my permalink to say (e.g. portfolio, post, etc)

http://mysite/?portfolio=xxxx&param=whatever

I need the param, because the post itself defines the "whatever" parameter and there is a search form in the post, which initializes itself using this parameter (the searchform gets the parameter, if it's in URL). For single links, I could've placed the param into the link, but the WP defines the permalinks restrictively.

I tried adding add_query_arg() to functions.php without success (It's not even clear where to place the code (single.php or functions.php) and how to call the function from the post).

I then tried adding custom fields and Meta Boxes, but they seem to conatin the extra parameter but not add it to the URL. So all I get is:

http://mysite/?portfolio=xxxx

a.) BEST SOLUTION The best way would be, to add a custom field to the post (or post type), which inserts a value the param and shows the permalink-URL with that parameter.

b.) JUDO SOLUTION The simplest thing would be, to add this parameter (text) to the link.

There are a gazillion post about this online, but they all refer to parsing of parameters which external links pass ($_GET) and conditionally change the appearance of the site or adding one specific parameter/value to each post/page. I do not need this.

Is there any way to add this 1 single parameter to the permalink-URL directly from the post, without changing 18 php files and writing hundred lines of code?

Thank you for any help!

m

PS. I am using WP 3.6.1 DE with inovado

.

Things I have already tried


  1. WP Codex add_query_arg()
  2. Stackoverflow: question 4586835 how-to-pass-extra-variables-in-url-with-wordpress
  3. Cookie-monster: wordpress-url-parameter-utility
  4. Creativebloq: user-friendly-custom-fields-meta-boxes-wordpress-5113004
  5. Farinspace: how-to-create-custom-wordpress-meta-box
  6. stackexchange: questions 51444 - add-extra-parameters-after-permalink

and finally

  1. webopius: using-custom-url-parameters-in-wordpress
Share Improve this question asked Oct 1, 2013 at 14:59 Ali MIkkael GültekinAli MIkkael Gültekin 11 silver badge1 bronze badge 1
  • Forgot to say: the form is defined elsewhere, is generic. (formidable) – Ali MIkkael Gültekin Commented Oct 1, 2013 at 15:01
Add a comment  | 

2 Answers 2

Reset to default 1

The Codex page for post_link has an example similar to what you need. For custom post types, there's also the post_type_link filter.

This would go in your theme's functions.php, and checks if a meta key query_arg exists, and appends it to the URL if so:

function wpa_post_link( $url, $post ){
    if ( $meta = get_post_meta( $post->ID, 'query_arg', true ) ) {
        $url = add_query_arg( 'param', $meta, $url );
    }
    return $url;
}
add_filter( 'post_link', 'wpa_post_link', 10, 2 );

I don't know if I understood your question correctly, but ...

<a href="'. get_the_permalink($post->ID) . '?extraParam=xxx' .'">

Something like that is not enough?

本文标签: custom fieldAdding an extra parameter string to my posts39 permalink