Skip Navigation

[Resolved] Looking to draw out a list of users that have a published directory

This thread is resolved. Here is a description of the problem and solution.

Problem:
Looking to draw out a list of users that have a published directory

Solution:
To display the list of users who do not have directly published post, you will have to use the view's filter: "wpv_filter_user_query"

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/looking-to-draw-out-a-list-of-users-that-have-a-published-directory/#post-2059255

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

This support ticket is created 2 years, 11 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by joannaH 2 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2052429

It seems I can build a view that might get me what I want but wanted to make sure I am proceeding properly with your plugin. We have users marked as contributors (about 300) and we have 200 of them with published directory listings. Can you help me with the best way to pull a list of the 100 that have not submitted a listing? To be clear, they have submitted a form to create an account but have not yet added content. We want to identify them.

Additionally, along the same lines, we have these users that have created an account but would like an automated way to switch their role once they have submitted a form to post content. Is this possible with your software?

#2052951

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To display the users list who do not have added any posts, we will have to find first all users who have publish the posts and then we can use not in clause to get all users who do not have added any post.

For that we need to use the view's filter: wpv_filter_user_query
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_user_query

If you can share admin access details and tell me for what post type you want to check that user do not added any post to it.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2057299

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery for the original issue reported.

I suggest you to open a new ticket with every new question you may have.

For the original issue regarding the displaying the list of users who do not have directly published post.

I've created the following view that query the User role "Contributor:
=> hidden link
[ you can adjust the "loop output" section and display what ever fields you want to display it]

With "Custom Code" section I've added the following code:
=> hidden link

add_filter( 'wpv_filter_user_query', 'func_filter_wihout_publish_posts_users',10,3);
 function func_filter_wihout_publish_posts_users( $query_args, $view_settings, $view_id) {
    if ( $view_id == 2578 ) {
       $query_args['has_published_posts'] = array('directory'); 
    }
    return $query_args;
}

I've created the following test page and saved it as a "Draft" where I've added the User view I've created above using the "Fields and Text" block:
=> hidden link

Now, if you can check on the frontend, it lists all users who do not have publish post on "directory" post type.
hidden link

#2058663

I believe this is a list of all the users that 'do' have a directory post. I am not sure where to filter or change so that is shows the ones that 'do not'. I have looked up a few of these users and they do have a listing.

#2059255

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ahh ok. To display the list of users who "Do Not Have" post with post type "directory".

I've adjusted the code added to "Custom Code" section as given under:

add_filter( 'wpv_filter_user_query', 'func_filter_wihout_publish_posts_users',10,3);
 function func_filter_wihout_publish_posts_users( $query_args, $view_settings, $view_id) {
   
  global $wpdb;
    if ( $view_id == 2578 ) {
       //$query_args['has_published_posts'] = array('directory'); 
      
   $users_having_posts =  $wpdb->get_col($wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users INNER JOIN $wpdb->usermeta ON ( $wpdb->users.ID = $wpdb->usermeta.user_id ) WHERE 1=1 AND $wpdb->users.ID IN ( SELECT DISTINCT $wpdb->posts.post_author FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type IN ( 'directory' ) ) AND ( 
  ( 
    ( $wpdb->usermeta.meta_key = 'mzd_capabilities' AND $wpdb->usermeta.meta_value LIKE '%\"contributor\"%' )
  )) ORDER BY $wpdb->users.user_login ASC"));
    	 
      $query_args['exclude'] = $users_having_posts;
            
        
    }
    return $query_args;
}

And When I see the list, I can confirm that it lists all users who do not have post created with post type "directory":
=> hidden link

#2059761

My issue is resolved now. Thanks for your help, I am not sure how I would have known how to do all that custom coding, is there documentation on creating these query statements?

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