WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. heatstroke
    Member
    Posted 1 year 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

    http://wordpress.org/plugins/simple-user-listing/

  2. helgatheviking
    Member
    Plugin Author

    Posted 1 year 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:
    http://wordpress.stackexchange.com/questions/31722/get-users-with-atleast-one-post
    and
    http://wordpress.stackexchange.com/questions/31443/how-to-list-users-that-have-written-custom-post-types-and-hide-the-ones-that-hav

    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
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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 ) );

    Regards

  5. helgatheviking
    Member
    Plugin Author

    Posted 1 year 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.

    Cheers.

  6. heatstroke
    Member
    Posted 1 year 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
    Member
    Plugin Author

    Posted 1 year 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.

  8. fsx
    Member
    Posted 3 months ago #

    Maybe I found a far more simple solution, as we already defined $num_posts in content-author.php

    Just change the Template like this:

    $user_info = get_userdata($user->ID);
    $num_posts = count_user_posts ( $user->ID );
    ?>
    <?php if ($num_posts != 0) echo '
    <div class="author-info author-block">
    <div class="author-avatar">'.get_avatar( $user->ID, 68 ).'</div>
    <div class="author-description"><h2><a href="'.get_author_posts_url($user->ID).'">'.$user_info->display_name.'</a></h2>
    <p>'.$user_info->description.'</p>
    <p class="author-beitraege"><a href="'.get_author_posts_url($user->ID).'">Lese'.$user_info->display_name.'s Beitr├Ąge</a></p>
    </div>
    </div>';
    ?>
  9. helgatheviking
    Member
    Plugin Author

    Posted 3 months ago #

    Won't that make the pagination a little hinky?

  10. fsx
    Member
    Posted 3 months ago #

    you're right, but if you don't need pagination, for the dumber ones like me, it's ok.

  11. starflow
    Member
    Posted 3 months ago #

    Sorry I got confused, what was the definitive answer here?

  12. helgatheviking
    Member
    Plugin Author

    Posted 3 months ago #

    The definitive answer is that posts_per_author (or equivalent) is not a parameter that is supported by WP_User_Query and thus is not supported by SUL. There are potentially some workarounds out there, but they are presumably complex, and not supported by me.

  13. starflow
    Member
    Posted 3 months ago #

    Sorry, I am still none the wiser. Do you have an example of how to use that posts_per_author (or equivalent)?

  14. starflow
    Member
    Posted 3 months ago #

    This thread as marked as [resolved] which bit is resolved? I tried the solution by fsx, but that produced a blank page.

  15. helgatheviking
    Member
    Plugin Author

    Posted 3 months ago #

    The thread is marked as resolved as the question cannot be solved using normal means. posts_per_author does not exist as a parameter. Please see the codex article on WP_User_Query for a list of valid parameters. Since SUL relies on WP_User_Query any parameters not supported or part of WP_User_Query are not supported or available in SUL.

    Fsx's solution is a partial workaround (ie: it is probably ok if you don't need pagination, but otherwise may be problematic). I haven't tested it, but if you are seeing a white screen I presume it may include a typographical error.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.