[Resolved] get_author_posts_url() not working
Dunno why that isn’t working for you, however this works for me…
global $authordata; $post_author = "<span class=\"post-author\">".__('Author:')." <a href=\"".get_author_posts_url( $authordata->ID, $authordata->user_nicename )."\">".get_the_author()."</a></span>\r\n"; echo $post_author;
As for the redirect to the author.php template, no idea.. the author.php isn’t populated with anything but the author name being sent to it which then you need to load the data for that author..
example author.php: https://github.com/Frumph/easel/blob/master/author.php
Thank you very much Frumph for the snippet and author page example.
The code you offer (from the WordPress includes/author-template.php functions) also only generates “http://test/” instead of the full author posts URL. Very odd indeed. I am running this query inside a working posts loop.
I also tried the codex example for get_author_posts_url()
<a href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>"><?php the_author_meta('display_name'); ?></a>
but that delivers the same error, only http://test
Interestingly: I am able to manually generate a posts page using this format:
but I’d rather have the meaningful /authors/ URL.
I have permalinks turned on, and a readable and (I presume,) correctly configured htaccess with the usual rewrites, so why wouldn’t
Eager to hear any ideas on how to debug this.
hrm. are you familiar with var_dump ?
Which would output the contents of the return of that
ah thanks for the reminder. I’m just getting back into a spot of PHP after many months.
get_the_author_meta(‘ID’) returns the correct post author ID. That was the first thing I checked, just using echo.
Since I can generate the author posts page using the query string URL ?author=[number] the problem seems to be something else.
I can manually make a workaround by crafting the author posts list URL using ?author=[ID], but I’d like to track down why I’m having a problem with the usual http:/domain/author/name URL.
note: I correct myself re the first post: the proper WP URL is “/author/” not “/authors/”
I’m working on getting a heavily hacked WP site back into normal WP form. I’ve looked at the db, and it seems normal, I don’t think that’s the problem here.
go set your settings -> permalink structure to the top one (no pretty permalink) and see what it returns then
thank Frumph for the debugging suggestion. I had remembered something about having to resave permalink settings, but, alas, that didn’t change anything.
I tried switching up and back between default and day/time permalink structures, and checking how that changes links.
I find that the pretty permalinks are working for all EXCEPT author pages. EDIT: and category pages. Tag pages work. Category pages don’t. (boggle.)
The post links generate nice permalinks, but author pages do not.
When I revert permalinks to the default structure, the correct author pages are generated (http://test/?author=24) and the author template is accessed.
I am unable to manually create a working pretty permalink for the author page.
mod-rewrite is enabled for Apache. (checked that.)
.. just for the record.. the get_author_posts_url … will not return an author page if the user hasn’t posted anything…users are not authors unless there is a post in their name
but I digress, so the default structure works but the permalink doesn’t, so which setting in the permalink tree are you using or are you setting your own?
solved my problem.
It’s the number one thing one tells anyone when they are having an unusual behavior in WordPress… what is it?
yes… “disable plugins.”
As it happens (since I was working on an old ill-maintained site with many unused plugins…)
I had a plugin called… wait for it… “Advanced Permalinks.”
It was so advanced that, even though there were no settings made in it (I checked) it still managed to break normal permalink behavior.
And thank you for your help Frumph, I’ve learned more!!
- The topic ‘[Resolved] get_author_posts_url() not working’ is closed to new replies.