Skip Navigation

[Resolved] Need help about redirection of Single Author Archive

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#1558391

Tell us what you are trying to do?
Hi to all,
so, I'm building a new theme to my Event Site using Toolset, View, Form, Block editor in Content Template and sometimes Divi.
Because I don't use Block plugin but I use View, for me, it is not too fast building the Author Posts Archive content template without using Toolset Content Template section...
Well, I have created a new CPT called "Autore", and with Content Template I have create the "Autore" single page layout. With View I permit to every Author to create only one CPT "Autore" single post.
Using the following custom code, I have redirected the Author Posts Archive Page to the relative CPT "Autore" single post where I display the general information about the Author and a search filter with the posts list, and with another plugin I will redirect the Authors Archive to the CPT "Autore" Archive.
In every Event post, I have added a link to the Author Post Archive that with the following code is redirect to its relative CPT "Autore" single post.
Now, here, the custom code I have mentioned above:

add_action( 'template_redirect', 'redirect_author_archive_to_staff_profile' );
 
function redirect_author_archive_to_staff_profile() {
 
    if ( is_author() ) {
        $author = get_the_author_meta('ID');
        if($author) {
            $args = array(
                'author' => $author,
                'post_type' => 'autore',
                'post_status' => 'publish',
                'posts_per_page' => 1
            );
            $author_posts = new WP_Query( $args );
            if( $author_posts->have_posts() ) {
                while( $author_posts->have_posts() ) {
                    $author_posts->the_post();
                    $author_bio_post = get_the_ID();
                    $authorProfileUrl = get_permalink($author_bio_post);
                }
                wp_reset_postdata();
            }
        }
        wp_redirect( $authorProfileUrl, 301 );
        exit;
    }
}

Now, because my site is populated with more Events posts and more Authors, for the existing authors, on clicking the link to them Author Posts Archive that not have created them CPT "Autore" single post, the redirection returns a White Page...

Is it possible, for Every Authors that not have created them CPT "Autore" single post, when they try to create new Event post or login into the site (the registration and login are managed by Indeed Ultimate Membership Pro) to be redirected to the CPT "Autore" single post Creation FORM?

Is there any documentation that you are following?
I don't know.

Is there a similar example that we can see?
I don't know.

What is the link to your site?
This link is my CPT "Autore" single post: hidden link
but the original Author Post Archive is hidden link

This is the link about another Author Post Archive that not has created his own CPT "Autore" single post that is redirect to white page: hidden link

#1559497

Hello,

For the question:

for Every Authors that not have created them CPT "Autore" single post, when they try to create new Event post or login into the site (the registration and login are managed by Indeed Ultimate Membership Pro) to be redirected to the CPT "Autore" single post Creation FORM?

It depends on the plugin "Ultimate Membership Pro".

In Toolset side, you can create a post form for creating "Autore" single post, and display it in a WordPress page.

If it is WordPress built-in login form, you can try with filter hook to trigger the custom PHP function.
https://developer.wordpress.org/reference/hooks/login_redirect/

In this PHP function, redirect users to different URLs on your custom condition.

I suggest you check it with plugin author of "Ultimate Membership Pro", check what filter hook can do the same job.

#1561749

Thank you for your reply Lou.
But I think that I will use a View to display the Create Form about the CPT "Autore".
Well, in the home, I will add two conditions logic. The first for not logged users and they will display the standard content template for the homepage. The second for the logged in users, and here I add the View shortcode where if the logged in users not have created their own CPT Autore post, it will display the Form to create the CPT Autore post, if they have created it, the View will display the Homepage content template.
And this for all other pages.
Can I do that? Is it right?

#1562251

In my opinion, it does not needs custom codes.

For example, in the home page you mentioned above:
1) for not logged users.

You can use Toolset Access shortcode [toolset_access] to display different result for guests and logged-in users:
https://toolset.com/documentation/user-guides/access-control/access-control-texts-inside-page-content/

2) users not have created their own CPT Autore post
You setup a post view:
- Query own CPT Autore posts
- Fiter by post's author is current logged-in user:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
- If there isn't any result found, within shortcode [wpv-items-found] ... [/wpv-items-found]
Display the post form for creating new own CPT Autore post
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-found

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.