[Resolved] Show custom posts by author

Home Forums Support [Resolved] Show custom posts by author

Home Forums Support Show custom posts by author

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1150887
    Kaleem

    Hello Sir, I will like to display author’s custom posts instead of showing all other posts by the same author. Please kindly help me achieve that.
    Thank you for your wonderful work.

    #1151427
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’m not sure I understand – what do you mean by custom posts?

    #1151824
    Kaleem

    I’m trying to create a website and allow authors to submit two different posts (1. blog post 2. custom post type). So what I want to achieve is that I want to have two different links, one for displaying author “blog posts archive” and the other link for displaying “author post type archive” for the same author. So that when a user clicks on the “link 1” it only shows the blog posts for that author, and if the user clicks on “link 2” it shows the custom posts type for that same author.

    Thank you so much.

    #1151827
    Kaleem

    Currently, the Author Posts Link shows both the blog posts and the custom post type of author.
    But I want them separates.

    #1152226
    Tom
    Lead Developer
    Lead Developer

    Hmm, that might be tough.

    We could try something like this:

    add_action( 'pre_get_posts', function( $query ) {
        if ( ! $query->is_main_query() || is_admin() ) {
            return;
        }
    
        if ( is_author() ) {
            $post_type = $_GET['post_type'];
    
            if ( isset( $post_type ) ) {
                $query->set( 'post_type', esc_attr( $post_type ) );
            }
        }
    } );

    Then you should be able to do this:

    yoursite.com/author/username?post_type=your_custom_post_type
    yoursite.com/author/username?post_type=post
    #1152366
    Kaleem

    I put the code in functions.php but it still couldn’t work.

    After a thorough search, I found the following similar to what I want: https://wordpress.org/support/topic/show-custom-post-type-archive-by-author/

    Still, I couldn’t do it.
    Please have a look at the link, I strongly believe you will understand the code better.
    Thanks a lot.

    #1152424
    Tom
    Lead Developer
    Lead Developer

    That code likely won’t work in this case. Is my code still active on your site? If so, can you share your URL and the name of the custom post type?

    #1153697
    Kaleem

    Thank you so for your effort to help me solve this problem. In fact, I need that feature badly.

    The site is in Coming Soon mode, so I have emailed you with the details.
    Thanks a lot.

    Note:
    1. this url displays Page not found: yoursite.com/author/username?post_type=your_custom_post_type

    2. this one displays normal author posts without filtering the Custom post type: yoursite.com/author/username?post_type=post

    #1154392
    Tom
    Lead Developer
    Lead Developer

    I’m not seeing any posts with the resolved post type assigned to that author, even when I view the standard author archives.

    I’m not 100% sure my code will work, but it should in theory. If not, you may need to hire a developer to write a custom solution for you.

    #1154594
    Kaleem

    Ok, then I must crosscheck my codes very well.
    Thank you very much for your effort.

    #1154701
    Tom
    Lead Developer
    Lead Developer

    No problem!

    #1158550
    Kaleem

    Hi, your solution was PERFECT! The whole problem caused by me due to improper creating of my CPT.
    Thank you so much for this solution.

    #1158990
    Tom
    Lead Developer
    Lead Developer

    Awesome! Glad I could help 🙂

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.