[Resolved] Display author bio only if they have posts

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.

Our next available supporter will answer your ticket in about 7.89 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  Dave 2 months ago. The support staff assigned to this topic is Luo Yang.

Viewing 3 posts - 1 through 3 (of 3 total)
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

Luo Yang
Forum moderator

Supporter languages: English (English ) Chinese (Simplified) (简体中文 )

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

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://wp-types.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!

Viewing 3 posts - 1 through 3 (of 3 total)