Shortcode to Selectively Display Published Users Only
-
Hello,
Is there a way to selectively display only those users who have published posts? My site has regular readers and authors (both with user role of a subscriber).
How can I generate and display a list of only those with published posts (and provide an exclusion for, say admins)? What could be a valid shortcode for such a query?
Kind regards,
Abhijeet
-
This topic was modified 8 years, 5 months ago by
backpackingseries.
-
This topic was modified 8 years, 5 months ago by
-
Hello, backpackingseries!
Thank you for writing in.
We a bit confused here.
What are you using to make subscriber able to publish posts? Are the posts credited to the registered subscriber?
Do you want to generate a list of all authors or are you still referring to the Author Box below the post?
If you just want to create a page with all author boxes then you can use the shortcode
[ultimate_author_box user_id="1"]With the user_id parameter, you can refer to the How to use section of the plugin for further detail reference.
Any further elaboration would be a great help.
Thank you!
Hi @scottbadger
Thank you for your response and the query. My apologies there. I should have been specific.
What are you using to make subscriber able to publish posts? Are the posts credited to the registered subscriber?
I am using this snippet from Stackexchange to list all users in the dropdown list. It allows me to assign authorship to any subscriber without a corresponding increase in backend role. However, not all subscribers have published posts.
Do you want to generate a list of all authors or are you still referring to the Author Box below the post?
Yes, I want to generate a list of all authors to display on a specific page. For all practical reasons, your brilliant plugin replaces my author template.
If you just want to create a page with all author boxes then you can use the shortcode [ultimate_author_box user_id=”1″]
I am using this method at the moment. But it stands the risk of oversight (accidental exclusion) and an added administrative step after each post is published. I would like to automate this process – as if this is my author template page.
I would really appreciate your advise to achieve this.
Kind regards
Abhijeet
Hello, backpackingseries!
Thank you for writing back.
Just to be clear, you just want to create a Author Archive page?
If you want a dynamic code then try this:
If you are using php, you can simply use get_user_meta( ) to get an array of user details, run a foreach loop, fetch the user id, use count_user_posts to check if the current user has any posts and run the shortcode only if there is any post.
Hope this helps.
Thank you!
Hi @scottbadger
Thanks very much once again. Yes, I want to create a custom author-archive page using your plugin. (I do not want to use the default WordPress author archive)
I was hoping to achieve this with an Ultimate Author Box Lite shortcode but it sounds tad bit more complicated than that! π I am not much of a programmer and have only managed to stitch together a site-specific plugin (PHP) with code snippets from helpful developers, like yourself, on Stackexchange and WordPress forums.
So, if I may ask: are you suggesting to insert a code (1) in my (PHP) site-plugin or (2) on the custom page for site authors? Any further instructions are welcome. Also, would you have a snippet for me to try? Please advise.
Kind regards
Hello, backpackingseries!
Thank you for writing back.
I thought you had already figured our where to modify the code( my bad).
If I had to do it, I could create a theme page template and write all the code there and then simply assign the page template to one of the page created from WordPress and call it my Author List page.
Reference: http://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/
I would leave the plugin code as it is and just create a additional theme page template .
You can use the
<?php add_filter( 'author_link', 'filter_function_name' ) ?>Reference: https://codex.wordpress.org/Plugin_API/Filter_Reference/author_link
filter to then overwrite the default author link url and use it to redirect the link to your new author page.
Thank you!
Hi @scottbadger
Thanks very much for that direction π I think I can manage to create the custom page template and try some code with count_user_posts conditional check.
Should there be a plan to include such a feature (that allows using a shortcode with a parameter, say,
[ultimate_author_box displayusers="all" user_has_posts="true"]) in your plugin’s future versions, I would be delighted to update!Kind regards,
Abhijeet
Hello, @backpackingseries!
Hope it would all work out for you. Unfortunately, currently we do not have any plans to do so. May be if we get further such requests in the future we just might.
Regards!
Thank you @scottbadger
On another note, I am surprised with the modest levels of installs of your plugin. As I have said in my 5-star review, it sets a new benchmark for author-display plugins. I sincerely wish it picks up soon and you get more such requests π
Kind regards
The topic ‘Shortcode to Selectively Display Published Users Only’ is closed to new replies.