I have a follow-up question to this answer here: Create guest author page via php

I would like to modify the get_author_posts_url function to get a custom taxonomy guest author slug. I need this because right now the Author URL is not matching the name of the guest author slug, it is showing the slug of the name of the user that created the post (admin). So far I have taken the following steps:

  1. I created a custom taxonomy for Guest Author (autoria), using the plugin Custom Post Type UI
  2. Then I used this filter to register the guest author as the post author in WP panel:
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );
function guest_author_name( $name ) {
    global $post;
    $author = wp_get_post_terms( $post->ID, 'autoria', array( 'fields' => 'names' ) );
 $author = implode( ', ', $author );
    if ( $author )
    $name = $author;
    return $name;

So now I have the guest author base and slug such as mywebsite.com/autoria/guest-author, and it correctly displays the list of posts by that guest author.

Then I modified the author base with the following code:

 function change_author_permalinks()  
      global $wp_rewrite;  
      $wp_rewrite->author_base = 'autoria'; 
      $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base. '/%author%';  

The problem is that when I try to dynamically redirect it using Author_URL it doesn't show the guest-author slug but the slug of the user that created the post, such as the admin. So the only way I could fix this was to create a custom field called guest-author-url and then manually fill all posts' with this information to redirect to this custom field.

I would like to change the following function to fetch the guest author taxonomy link instead, so it can be dynamic:

    function get_author_posts_url( $author_id, $author_nicename = '' ) {
    global $wp_rewrite;

    $author_id = (int) $author_id;
    $link      = $wp_rewrite->get_author_permastruct();

    if ( empty( $link ) ) {
        $file = home_url( '/' );
        $link = $file . '?author=' . $author_id;
    } else {
        if ( '' === $author_nicename ) {
            $user = get_userdata( $author_id );
            if ( ! empty( $user->user_nicename ) ) {
                $author_nicename = $user->user_nicename;
        $link = str_replace( '%author%', $author_nicename, $link );
        $link = home_url( user_trailingslashit( $link ) );

It would save me so many hours of manually filling the link of the guest authors one by one.

Thanks so much for any help

  • I'm not at all familiar with elementor, but based on what i'm able to see i'd suggest looking at removing whatever author element you use and replacing it with a taxonomy one, any generated taxonomy links for guest_author would link to their respective term (guest author) pages and you'd not have to jiggle around author details with filters.
    – t31os
    Oct 22, 2022 at 2:51
  • I've learned that I can register new dynamic tags, for example for a a custom Author URL, I just don't know which function could fetch the taxonomy guest-author pages' URLs and pass it to this dynamic tag. Do you have any idea how could that be done? Thanks
    – usina
    Oct 22, 2022 at 13:27
  • This is probably a question better taken up with Elementor support. In theory it shouldn't be all that hard if the right hooks/plugs are available, but given it's a heavily paywalled plugin that i have zero experience with it, i'm really not qualified to advise on how best to approach this.
    – t31os
    Oct 22, 2022 at 15:42
  • The dynamic tags page suggests you can load in post terms, as long as that supports custom taxonomies, it should be a matter of replacing the author element/block in your page with a dynamic tag that loads in the post terms for guest_author.
    – t31os
    Oct 22, 2022 at 15:52
  • I will edit the post to ask for Wordpress / PHP answers, instead of a Elementor one. I think creating a dynamic tag would be a possible approach but also creating a filter, as you've helped me do in the case of the author's name and slug.
    – usina
    Oct 22, 2022 at 19:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.