admin管理员组文章数量:1122832
I use a WP template to generate an email newsletter. I display future posts and until recently using the_permalink displayed the full human-readable URL (e.g. /this-is-a-page). Now it displays the post ID URL (e.g. ?p=5800). How do I get WP to display the human-readable URL?
More strange, perhaps, on the Add/Edit page for my future entries, when I add or update a story to be published in the future, the message up top "Post updated. View post" link goes to the post ID URL. However, the View Post button to the right of the Permalink, located directly under the entry title input field, goes to the human-readable URL.
It's a major PITA and totally counter-productive to manually convert the post URLs to human readable URLs. I need the HTML output from my template to set up HTML emails before the stories are published.
Any ideas how to retrieve and display human-readable URLs for future stories?
Thanks for any help and insights.
I use a WP template to generate an email newsletter. I display future posts and until recently using the_permalink displayed the full human-readable URL (e.g. /this-is-a-page). Now it displays the post ID URL (e.g. ?p=5800). How do I get WP to display the human-readable URL?
More strange, perhaps, on the Add/Edit page for my future entries, when I add or update a story to be published in the future, the message up top "Post updated. View post" link goes to the post ID URL. However, the View Post button to the right of the Permalink, located directly under the entry title input field, goes to the human-readable URL.
It's a major PITA and totally counter-productive to manually convert the post URLs to human readable URLs. I need the HTML output from my template to set up HTML emails before the stories are published.
Any ideas how to retrieve and display human-readable URLs for future stories?
Thanks for any help and insights.
Share Improve this question asked Jul 19, 2015 at 4:09 FredHeadFredHead 3101 gold badge4 silver badges10 bronze badges3 Answers
Reset to default 2Permalink settings are available under Permalinks
under the settings
menu.
I have faced a similar issue resetting the options here to non rewritten URLs and then back to the rewritten URLs should reset any issues with .htaccess
file
Just came across this same issue.
A wordpress moderator recommended using the post_link
hook if you don't mind people knowing your future permalinks. This needs to be added in your functions.php
file
functions.php
add_filter( 'post_link', 'future_permalink', 10, 3 );
function future_permalink( $permalink, $post, $leavename ) {
/* for filter recursion (infinite loop) */
static $recursing = false;
if ( empty( $post->ID ) ) {
return $permalink;
}
if ( !$recursing ) {
if ( isset( $post->post_status ) && ( 'future' === $post->post_status ) ) {
// set the post status to publish to get the 'publish' permalink
$post->post_status = 'publish';
$recursing = true;
return get_permalink( $post, $leavename ) ;
}
}
$recursing = false;
return $permalink;
}
Thanks to Alexander Gounder in the comments of this page for finding the solution. I've added it here for clarity.
Thanks so much for your helpful solution, Adam! Today I stumbled upon exactly the same issue that @Don is mentioning in his little comment:
This is useful but it doesn't restore the old value of post_status when it's done. If any subsequent check is done to $post->post_status it's going to think it's published, not future
Which is actually an issue, as it might make future posts (or worse, drafts if you change the function to handle these as well!) available to the public in a context where you might not want it.
But there is a simple solution to this problem. clone
the $post before returning the permalink, like so:
add_filter( 'post_link', 'future_permalink', 10, 3 );
function future_permalink( $permalink, $post, $leavename ) {
/* for filter recursion (infinite loop) */
static $recursing = false;
if ( empty( $post->ID ) ) {
return $permalink;
}
if ( !$recursing ) {
if ( isset( $post->post_status ) && ( 'future' === $post->post_status ) ) {
// clone the post before changing it's status
$clone = clone $post;
// set the post status to publish to get the 'publish' permalink
$clone->post_status = 'publish';
$recursing = true;
return get_permalink( $clone, $leavename ) ;
}
}
$recursing = false;
return $permalink;
}
本文标签: permalinksthepermalink displays post ID URL for future posts
版权声明:本文标题:permalinks - the_permalink displays post ID URL for future posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311369a1934712.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论