Opened 4 years ago
Closed 3 years ago
#9466 closed defect (bug) (wontfix)
Drop %tag% support in permalinks
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | Permalinks | Version: | 2.7.1 |
| Severity: | minor | Keywords: | needs-patch |
| Cc: |
Description
function get_permalink($id = 0, $leavename = false) not support %tag%
My variant this function:
function get_permalink($id = 0, $leavename = false) {
$rewritecode = array(
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
$leavename? : '%postname%',
'%post_id%',
'%category%',
'%tag%',
'%author%',
$leavename? : '%pagename%',
);
if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter )
$post = $id;
else
$post = &get_post($id);
if ( empty($post->ID) ) return false;
if ( $post->post_type == 'page' )
return get_page_link($post->ID, $leavename);
elseif ($post->post_type == 'attachment')
return get_attachment_link($post->ID);
$permalink = get_option('permalink_structure');
if ( != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
$unixtime = strtotime($post->post_date);
$category = ;
if ( strpos($permalink, '%category%') !== false ) {
$cats = get_the_category($post->ID);
if ( $cats ) {
usort($cats, '_usort_terms_by_ID'); order by ID
$category = $cats[0]->slug;
if ( $parent = $cats[0]->parent )
$category = get_category_parents($parent, false, '/', true) . $category;
}
show default category in permalinks, without
having to assign it explicitly
if ( empty($category) ) {
$default_category = get_category( get_option( 'default_category' ) );
$category = is_wp_error( $default_category ) ? : $default_category->slug;
}
}
add tag to permalink
$tag = ;
if ( strpos($permalink, '%tag%') !== false ) {
$tags = get_the_tags($post->ID);
if ( !empty( $tags ) ) {
usort($tags, '_usort_terms_by_ID'); order by ID
$tag = $tags[0]->slug;
}
}
$author = ;
if ( strpos($permalink, '%author%') !== false ) {
$authordata = get_userdata($post->post_author);
$author = $authordata->user_nicename;
}
$date = explode(" ",date('Y m d H i s', $unixtime));
$rewritereplace =
array(
$date[0],
$date[1],
$date[2],
$date[3],
$date[4],
$date[5],
$post->post_name,
$post->ID,
$category,
$tag,
$author,
$post->post_name,
);
$permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
$permalink = user_trailingslashit($permalink, 'single');
return apply_filters('post_link', $permalink, $post, $leavename);
} else { if they're not using the fancy permalink option
$permalink = get_option('home') . '/?p=' . $post->ID;
return apply_filters('post_link', $permalink, $post, $leavename);
}
}
Attachments (1)
Change History (31)
- Resolution set to invalid
- Status changed from new to closed
additioanlly: please chekcout on how to upload patches. Wordpress uses SVN, get SVN and create a patch. upload the patch. .patch files are automatically highlihgted so that other developers see, what has been changed.
thanks.
- Resolution invalid deleted
- Status changed from closed to reopened
Replying to hakre:
it does not support %tag% because there is and is no place for %tag%. that is simply bogus.
http://codex.wordpress.org/Using_Permalinks - Choosing your permalink structure
"%tag%
A sanitized version of the tag name (tag slug field on New/Edit Tag panel)."
but it does not work, probably a mistake
- Resolution set to invalid
- Status changed from reopened to closed
the function is about POSTS, not TAGS: (quote from docs:) Retrieve full permalink for current post or post ID.
the link you provide ( http://codex.wordpress.org/Using_Permalinks ) states it clearly as well: this link is about the UI, the ACP, the ADMIN, the BACKEND, it has nothing to do with the function in wordpress core you reference.
still the same, still close. feel free to re-open but please provide something seriously. forexample that that function is not properly working with IDs of a Post.
- Keywords needs-patch added; permalink tag removed
- Milestone changed from Unassigned to 2.8
- Resolution invalid deleted
- Status changed from closed to reopened
- Summary changed from Not work %tag% in permalinks to %tag% not handled properly in get_permalink
The posters request is valid.
Currently the Permalink Documentation specifies that %tag% along with, %category% are valid within the Permalink structure.
WP_Rewrite is aware that %tag% is valid(see http://core.trac.wordpress.org/browser/trunk/wp-includes/rewrite.php#L611), However, get_permalink() is not(see http://core.trac.wordpress.org/browser/trunk/wp-includes/link-template.php#L81 ), So it returns a bad permalink when %tag% is used. (It doesnt get replaced)
- Keywords has-patch added; needs-patch removed
attachment 9466.diff added
gashek's code in diff form
Note, That is a post doesnt have a tag, the generated url will be in-accessable.
Note, that Performance is severly affected by the usage of %tag%,%category% or %author% at the start of the permalink structure.
- Keywords needs-testing added
comment:9
follow-up:
↓ 12
Denis-de-Bernardy — 4 years ago
- Keywords needs-patch added; has-patch needs-testing removed
patch isn't working.
- Milestone changed from 2.8 to Future Release
- Priority changed from normal to low
- Severity changed from normal to minor
punting to future, pending a patch that works
see also #9269
comment:12
in reply to:
↑ 9
DD32 — 4 years ago
Replying to Denis-de-Bernardy:
patch isn't working.
...And by that you mean?
If you test something, Report back on whats actually wrong would you???
- Keywords has-patch tested 2nd-opinion added; needs-patch removed
well, the obvious: when I applied the patch, permalinks had %tag% in them, instead of the actual tag. :-)
I just tested it again, though, and it now seems to work. mmm...
one slight issue I'd have with this one, however, is that, when no tag is present, the /%tag%/%postname%/ permalink becomes title/.
comment:14
DD32 — 4 years ago
Yep, The blank-item was something i mentioned in my attachment comments.
It'd happen with the category as well if it wasn't for the fact of the default category.
Another option might be to automatically create the %taxonomy-query-arg% when new taxonomies are added.. but that'd need back-compat for categories and possibly tags.. and possibly change the entire way the WP_rewrite/WP_query classes operate..
comment:15
ryan — 4 years ago
How about we remove support for any taxonomy other than category from the permalink structure? We shouldn't encourage such things because of performance reasons and because of the lack of a default. %tag% is already broken, so nothing lost.
comment:16
DD32 — 4 years ago
Hm... Sounds good to me actually. It'll be far better off in the long run.
Should be able to be added by a plugin if anyone actually really wants it too.
the issue is, we'd then need to add the needed filters over at the whether we should use verbose page rules, and so on. we could be certain someone out there will forget to ues them if we do.
comment:18
DD32 — 4 years ago
If someone makes a plugin to do it, then yes, they'd need to enable verbose rules.
How about removing $this->use_verbose_page_rules = false; explicitly in the check, And only set it to true there. That way, Any plugin could do a GLOBALS[wp_rewrite]->use_verbose_page_rules = true;
suggesting wontfix for this one.
comment:20
dd32 — 4 years ago
Lets strip the rest of the current %tag% support out and call this fixed that way instead.
- Keywords needs-patch added; has-patch tested removed
- Milestone changed from Future Release to 2.9
- Owner changed from ryan to Denis-de-Bernardy
- Status changed from reopened to accepted
ok
- Summary changed from %tag% not handled properly in get_permalink to Drop %tag% support in permalinks
- Keywords 2nd-opinion removed
comment:24
hakre — 4 years ago
+1 for stripping %tag% support out of the permalinks. the whole permalinks concept needs more genreal consideration first.
- Owner Denis-de-Bernardy deleted
- Status changed from accepted to assigned
comment:26
johnbillion — 4 years ago
I believe this is fixed
comment:27
johnbillion — 4 years ago
Fixed as in %tag% support has been dropped from permalinks
comment:28
scribu — 4 years ago
- Resolution set to fixed
- Status changed from assigned to closed
what johnbillion said.
comment:29
scribu — 3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
comment:30
scribu — 3 years ago
- Milestone 2.9 deleted
- Resolution set to wontfix
- Status changed from reopened to closed

it does not support %tag% because there is and is no place for %tag%. that is simply bogus.