Forum Replies Created

Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter Aleksandr

    (@sshurick)

    For some unknown reason wordpess does not pass $user_id to my filter. So I get an error:
    PHP Warning: Missing argument 2 for aa_get_user_postcount() in /var/www/html/wp-content/plugins/site-plugin/site-plugin.php

    This is the code I’m using in my site-plugin.php:

    function aa_get_user_postcount( $total, $user_id ){
             error_log( $user_id.' has '.$total. 'posts' );
             return $total;
    }
    add_filter( 'aa_get_user_postcount', aa_get_user_postcount);

    It logs $total but not logs $user_id

    Thread Starter Aleksandr

    (@sshurick)

    Can you give me a code example please for this filter?

    apply_filters( "aa_get_user_postcount_{$blog_id}", count_user_posts( $user_id ), $user_id, $blog_id )

    I don’t understand what to do with $blog_id if my site is not using WPMU.

    Thread Starter Aleksandr

    (@sshurick)

    I need this only on one page, to display contributors of only one category. So I hardcoded it’s ID for simplicity.
    It would be ideal to show the post count for for that specific category and sort them by that count.

    For example Bob can have 2 posts in category #10 (for which we filter our output) and 200 in cat #1. And Jim has 100 posts in cat #10 and 2 in cat #1. I need to place Jim higher, then Bob in my list.

    Maybe filter aa_get_user_postcount can help me to adjust post count for users?

    Thread Starter Aleksandr

    (@sshurick)

    Found my fault. Finally came up with this function:

    
    function cat_user_list( $users ){
         foreach ( $users as $user ) {
    	   	 $args = array(
                     'author' => $user->user_id, //ID of the author
          	         'posts_per_page' => -1, //Retrieve all posts
                     'category' => 10 // Category to list, must be ID, as category is passed to WP_Query as cat
    	             );
         $posts_array = get_posts( $args );
         if ( count($posts_array) > 0 ) {
    	$filtered_users[] = $user;
            }       
         }
         return $filtered_users;  
    }
    add_filter( 'aa_user_raw_list','cat_user_list' );

    The only bad thing that post count is shown through the entire site, and I need post count in category.

    Thread Starter Aleksandr

    (@sshurick)

    Thanks for the reply, Paul!

    Tried this code in my site functions plugin:

    function aa_user_raw_list( $users ){
       error_log ('here!');
       return $users;
    }
    add_filter( 'aa_user_raw_list','aa_user_raw_list' );

    Nothing happened in /var/log/httpd/error_log.

    I’m using this string to filter users in a shortcode, if it matters:
    [authoravatars avatar_size=150 min_post_count=1 order=post_count sort_direction=descending show_postcount=true show_name=true page_size=50]

    Maybe I’m doing something wrong?

Viewing 5 replies - 16 through 20 (of 20 total)