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?
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
This is perfect. Thanks for the help, Luo!