Skip Navigation

[Resolved] Display author bio only if they have posts

This support ticket is created 6 years, 6 months 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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Dave 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#578358

Tell us what you are trying to do?
I have a page displaying all authors on a site. Not all of them have written a post yet, and I don't want them to show up on the Authors page until they have.

Is there any documentation that you are following?
I've looked at a few posts in Community Support, but nothing matches the conditions I have.

Is there a similar example that we can see?
Not that I'm aware of.

What is the link to your site?
hidden link

Note that your documentation states that wpv-posts-found is deprecated in favor of wpv-items-count in v1.3.1. I'm running Views 2.4.1, and the buttons in the Template composition area uses the deprecated code. In the cases listed below I tried both the deprecated and current code.

I've tried using these conditional statements:
[wpv-conditional if="( '[wpv-posts-found]' gt '0' )"] - the result was an empty content area. It displayed no authors.
For this test I also tried [wpv-conditional if="( '[wpv-posts-found]' > '0' )"] because "gt" instead of ">" seemed odd.)

[wpv-conditional if="( '[wpv-post-count]' ne '0' )"] ---do stuff--- [/wpv-conditional] – this gives me all the authors, even those with a post count of 0. I added [wpv-items-count] to see if Views is checking number of *posts* for the author it's displaying in the loop, but instead it's displaying 7 for every author. This means the conditional is actually checking the number of authors, not the number of posts for the author it's currently displaying.

So, is there a way to filter this display so it'll only show authors who've published a post?

#578431

Dear Dave,

I suggest you try with Views filter hook wpv_filter_user_query to apply parameter "has_published_posts" to the query, for example, add below codes into your theme/functions.php:

add_filter('wpv_filter_user_query', 'my_func2', 999, 3);
function my_func2($query_args, $view_settings, $view_id){
	if($view_id == 123){ //view's ID
		$query_args['has_published_posts'] = array('post', 'page'); //here setup post types
	}
	return $query_args;
}

Please replace 123 with your view's ID

More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query
https://codex.wordpress.org/Class_Reference/WP_User_Query#Has_Published_Posts_Parameter

#578623

This is perfect. Thanks for the help, Luo!

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