Forum Replies Created

Viewing 12 replies - 16 through 27 (of 27 total)
  • Thread Starter heatstroke

    (@heatstroke)

    Thank you for the reply, but this doesn’t work.

    Thread Starter heatstroke

    (@heatstroke)

    True, no need to change the search-author.php file, just realised it.

    This may be slower, but it is very important to me. I tried to add one more meta_key, like description, but then it became much slower, so I left only the two, first_name and last_name.

    Thread Starter heatstroke

    (@heatstroke)

    Hi people… 15 minutos later I did it. If someone needs the same, take note of this code. Now you can search by first name or last name in the same textfield.

    This is how I did it:

    search-author.php

    <?php
    /**
     * The Template for displaying Author Search
     *
     * Override this template by copying it to yourtheme/simple-user-listing/search-author.php
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    $search = ( get_query_var( 'first_name' ) ) ? get_query_var( 'first_name' )  : '';
    
    ?>
    
    <div class="author-search">
    	<h2><?php _e('Search authors by name' ,'simple-user-listing');?></h2>
    		<form method="get" id="sul-searchform" action="<?php the_permalink() ?>">
    			<label for="as" class="assistive-text"><?php _e('Search' ,'simple-user-listing');?></label>
    			<input type="text" class="field" name="first_name" id="sul-s" placeholder="<?php _e('Search Authors' ,'simple-user-listing');?>" value="<?php echo $search; ?>"/>
    			<input type="submit" class="submit" id="sul-searchsubmit" value="<?php _e('Search Authors' ,'simple-user-listing');?>" />
    		</form>
    	<?php
    	if( $search ){ ?>
    		<h2 ><?php printf( __('Search Results for: %s' ,'simple-user-listing'), '<em>' . $search .'</em>' );?></h2>
    		<a href="<?php the_permalink(); ?>"><?php _e('Back To Author Listing' ,'simple-user-listing');?></a>
    	<?php } ?>
    </div><!-- .author-search -->

    functions.php

    // Switch the WP_User_Query args to a meta search
    function kia_meta_search( $args ){
      // this $_GET is the name field of the custom input in search-author.php
        $search = ( isset($_GET['first_name'])) ? sanitize_text_field($_GET['first_name']) : false ;
        if ( $search ){
            // if your shortcode has a 'role' parameter defined it will be maintained
            // unless you choose to unset the role parameter by uncommenting the following
            //  unset( $args['role'] );
    		$args = array(
    	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    			'key'     => 'last_name',
    			'value'   => $search,
    			'compare' => 'LIKE'
    		),
    		array(
    			'key'     => 'first_name',
    			'value'   => $search,
    			'compare' => 'LIKE'
    		)
    	)
     );
        }
        return $args;
    }
    add_filter('sul_user_query_args', 'kia_meta_search');
    
    // Register query var and whitelist with Simple User Listing
    function kia_search_vars( $vars ){
        $vars[] = 'first_name';
        return $vars;
    }
    add_filter('sul_user_allowed_search_vars', 'kia_search_vars');

    Hope it helps ??

    Thread Starter heatstroke

    (@heatstroke)

    Ok,

    that would be one of the best features of the plugin, as nobody searches for usernames. People search for real names and surnames, no nicks.

    I tried the code you linked. It is the same es the one you posted in the FAQ section. It works when searching by one meta_key. The main problem for me is to use two meta_keys instead of one and make the search from one textfield.

    Anyway, I will keep trying it.

    Thank you ??

    Ok, I will see what is the best solution. My theme has already a navigation system integrated, so if I install WP Pagenavi, I will have to somehow disable the default navigation.

    Thank you ??

    ok, thanks ??

    I did it and for some reason did not work. I just created new user roles, deleted the old ones and after that I renamed the new ones again. This time it worked fine.

    Hi!

    Is there any chance to get a bit more detailed pagination?

    Actual patination is like <Previous Next>

    It would be nice to have something like <Previous 1 2 3 … N Next>

    Is it possible?

    Regards ??

    I am using the last version of the plugin. With [userlist] there is no problem, although when I put in a filter for a custom user role, the results are not the desired.

    It is a bit strange, because I have 2 new roles: Professional and Company

    When I use [userlist role=”Professional”], no user is listed. When I user [userlist role=”Company”], two Professional users appear (instead of Company users). So I am a bit confused whith this.

    Very good plugin although ?? The full list, without filters works well

    Thread Starter heatstroke

    (@heatstroke)

    Hi everyone!
    I am back with a small piece of code. This is the main line to retrieve all the comments recieved on all posts published by an author XXX.

    <?php
    $comments_count = $wpdb->get_var( "SELECT SUM(comment_count) FROM $wpdb->posts WHERE comment_count!='0' AND post_author='XXX'");
    echo "<p>Comments count: {$comments_count}</p>";
    ?>

    So if you want to retrieve a bit more information, here is how I did it:

    <?php
    $number 	= 3;
    $paged 		= (get_query_var('paged')) ? get_query_var('paged') : 1;
    $offset 	= ($paged - 1) * $number;
    $order_by = 'post_count'; // 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'
    $order = 'DESC';
    $avatar_size = 191;
    $blogusers = get_users('&offset='.$offset.'&number='.$number.'exclude='.$exclude.'&orderby='.$order_by.'&order='.$order);
    $users 		= get_users();
    $total_users = count($users);
    $total_query = count($query);
    $total_pages = intval($total_users / $number) + 1;
    
    foreach($blogusers as $q) {
    $u = get_the_author_meta('id', $q->ID);
    $comments_count = $wpdb->get_var( "SELECT SUM(comment_count) FROM $wpdb->posts WHERE comment_count!='0' AND post_author=".$u);?>
    
    <p><a href="<?php echo get_author_posts_url($q->ID); ?>"><?php echo get_avatar( $q->ID, $avatar_size); ?></a></p>
    <p>Name: <a href="<?php echo get_author_posts_url($q->ID);?>"><?php echo get_the_author_meta('display_name', $q->ID);?></a></p>
    
    <?php if (get_the_author_meta('description', $q->ID) != '') : ?>
      <p>Description:<?php echo get_the_author_meta('description', $q->ID); ?></p>
    <?php endif; ?>
    
    <p>Posts: <?php echo count_user_posts($q->ID);?></p>
    <p>Comments recieved on those posts: <?php echo $comments_count;?></p>
    <p></p>
    
    <?php } ?>
    
    <?php
    if ($total_users > $total_query) {
    echo '<div id="pagination" class="clearfix">';
    echo '<span class="pages">Pages:</span>';
      $current_page = max(1, get_query_var('paged'));
      echo paginate_links(array(
    		'base' => get_pagenum_link(1) . '%_%',
    		'format' => 'page/%#%/',
    		'current' => $current_page,
    		'total' => $total_pages,
    		'prev_next'    => true,
    		'prev_text'    => __('? Previous'),
    	'next_text'    => __('Next ?'),
    		'type'         => 'plain',
        ));}
    echo '</div>';
    ?>

    This one retrieves the avatar with a link to all the posts of the author, the name, number of posts created and the cound of comments recieved on them.

    It also has a pagination code, so if you have plenty of users to list, you can display a limited amount at a time.

    Note this is not formatted. You should display the info in divs and give some CSS rules to them.

    Hope this helped someone ??

    Thread Starter heatstroke

    (@heatstroke)

    Thank you Tara,

    I’ll take a look at those links.

    For now I am searching an ugly way to do it, by making a query with multiple tables, involving wp_comments (where the column comment_post_ID is relevant), wp_posts (post_author column) and wp_users (ID).

    In wp_users I will get the user ID. After that, in wp_posts, I will find what posts belong to that user and finally, in wp_comments I will count how many comments belong to those posts.

    I don’t really know how I am going to do that, but this is my plan for now ??

    Thread Starter heatstroke

    (@heatstroke)

    Thank you ??

    Although it doesn’t seem to be what I want to achieve. That script retrieves all the comments each user has made. What I need is the “opposite”: count the comments made each user’s posts and sum.

    This way I pretend to show how important an author is in the web, because if his posts recieve a lot of comments, we believe they are good posts. So the more comments an author recieves on his posts, the better.

    Thread Starter heatstroke

    (@heatstroke)

    Why not? I need to echo the categories names and IDs and Edit Flow does have categories…

Viewing 12 replies - 16 through 27 (of 27 total)