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¶m=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
- WP Codex add_query_arg()
- Stackoverflow: question 4586835 how-to-pass-extra-variables-in-url-with-wordpress
- Cookie-monster: wordpress-url-parameter-utility
- Creativebloq: user-friendly-custom-fields-meta-boxes-wordpress-5113004
- Farinspace: how-to-create-custom-wordpress-meta-box
- stackexchange: questions 51444 - add-extra-parameters-after-permalink
and finally
- 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¶m=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
- WP Codex add_query_arg()
- Stackoverflow: question 4586835 how-to-pass-extra-variables-in-url-with-wordpress
- Cookie-monster: wordpress-url-parameter-utility
- Creativebloq: user-friendly-custom-fields-meta-boxes-wordpress-5113004
- Farinspace: how-to-create-custom-wordpress-meta-box
- stackexchange: questions 51444 - add-extra-parameters-after-permalink
and finally
- webopius: using-custom-url-parameters-in-wordpress
- Forgot to say: the form is defined elsewhere, is generic. (formidable) – Ali MIkkael Gültekin Commented Oct 1, 2013 at 15:01
2 Answers
Reset to default 1The 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
版权声明:本文标题:custom field - Adding an extra parameter [string] to my posts' permalink? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741442417a2378996.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论