- This topic has 12 replies, 2 voices, and was last updated 4 years, 1 month ago by Tom.
-
AuthorPosts
-
January 31, 2020 at 3:06 pm #1150887Kaleem
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.February 1, 2020 at 9:17 am #1151427TomLead DeveloperLead DeveloperHi there,
I’m not sure I understand – what do you mean by custom posts?
February 1, 2020 at 11:38 pm #1151824KaleemI’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.
February 1, 2020 at 11:42 pm #1151827KaleemCurrently, the Author Posts Link shows both the blog posts and the custom post type of author.
But I want them separates.February 2, 2020 at 9:41 am #1152226TomLead DeveloperLead DeveloperHmm, 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
February 2, 2020 at 1:00 pm #1152366KaleemI 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.February 2, 2020 at 4:27 pm #1152424TomLead DeveloperLead DeveloperThat 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?
February 4, 2020 at 12:37 am #1153697KaleemThank 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_type2. this one displays normal author posts without filtering the Custom post type: yoursite.com/author/username?post_type=post
February 4, 2020 at 8:36 am #1154392TomLead DeveloperLead DeveloperI’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.
February 4, 2020 at 12:49 pm #1154594KaleemOk, then I must crosscheck my codes very well.
Thank you very much for your effort.February 4, 2020 at 3:44 pm #1154701TomLead DeveloperLead DeveloperNo problem!
February 7, 2020 at 10:21 pm #1158550KaleemHi, your solution was PERFECT! The whole problem caused by me due to improper creating of my CPT.
Thank you so much for this solution.February 8, 2020 at 9:45 am #1158990TomLead DeveloperLead DeveloperAwesome! Glad I could help 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.