Ready to get started?Download WordPress


Simple User Listing
[resolved] Show only users with at least 1 post (7 posts)

  1. heatstroke
    Posted 8 months ago #

    Hi everyone!

    I was wondering how can I modify the query to only list with at least one post. I want to ignore the users with 0 posts.

    Any ideas?

    Thank you


  2. helgatheviking
    Plugin Author

    Posted 8 months ago #

    This isn't a parameter that is supported by WP_User_Query, hence it isn't supported by SUL.

    These posts might be helpful:

    But you'll probably need to filter pre_user_query. That's the best I can do as this is too custom an implementation for me to support.

  3. heatstroke
    Posted 8 months ago #

    Useful links indeed :)

    My problem is, just as in other posts, to join these mysql queries with the plugin's script and using WP's coding.

    Will be searching arround, if I succeed, I will let you know.

    If someone has new ideas, they are welcome here ;)

  4. heatstroke
    Posted 8 months ago #

    Well, I could make it but my solution is useless for you because I have my database modified with a couple of custom columns.

    What I did was basically modify the plugin's code.

    Search for line 120:

    global $post, $sul_users, $user;

    after this line I have this:

    global $wpdb;
    $superarray = array();
    $exclude_users = $wpdb->get_results("SELECT ID FROM lw_users WHERE last_post_date = '0000-00-00 00:00:00'");
    foreach ($exclude_users as $us)
    { $superarray[] = $us->ID; }

    I changed line 126:

    'exclude' => '',

    and put my array in it, to exclude users I need:

    'exclude' => $superarray,

    so what you need to do is a query to retrieve the IDs of the users you want to exclude.

    It won't work just like this. It gave me an error, expecting array. So then I changed line 181 and just removed the whole line. Remove this

    $exclude = array_map( 'trim', explode( ',', $exclude ) );


  5. helgatheviking
    Plugin Author

    Posted 8 months ago #

    Maybe it would make more sense to select the IDs that you want to include? Instead of altering the plugin's code (you'll never never be able to update), I would advise that you filter the user query via pre_user_query. You can even pass a specific query_id in the shortcode parameters, or use the default id of simple_user_listing to specifically target my plugin's user query.


  6. heatstroke
    Posted 8 months ago #

    I use exclude because it is supposed to have less users with 0 posts than users with 1 or more posts.

    On the other hand, I don't really worry about the updates for now. I can always modify the code again.

    I don't know what is the pre_user_query and don't know how to pass a specific query_id in the shortcode. That would be uselful though...

  7. helgatheviking
    Plugin Author

    Posted 8 months ago #

    You pass a query id as a parameter the same way you pass any other parameter. [userlist query_id="users_with_post"]

    pre_user_query is like pre_get_posts for user queries. It lets you change the query arguments before the query is run.


You must log in to post.

About this Plugin

About this Topic


No tags yet.