DeadForce
Forum Replies Created
-
Forum: Plugins
In reply to: [Simple User Listing] New FilterIt works, thank you very much.
Now I came across another problem, the number of users that $sul_users->get_total() gives varies from page 1 to page 2 which is breaking my pagination.
I’ll try to find a cause but any help is appreciated.
Thanks in advance.
Forum: Plugins
In reply to: [Simple User Listing] New FilterIn simple-user-listing.php I added:
$sul_users = new WP_User_Query( $args ); // The authors object. $users = $sul_users->get_results(); //new filter $users = apply_filters( 'sul_users_results', $users, $list_id ); //conditional if ( empty ($users) ) { $users = $sul_users->get_results(); } do_action( 'simple_user_listing_before_loop', $list_id );
and in function.php I added this functions
function kia_meta_search( $args ){ // this $_GET is the name field of the custom input in search-author.php $search = ( isset($_GET['as']) ) ? sanitize_text_field($_GET['as']) : false ; if ( $search ){ /* There's a reason we're adding the action from here, you'll see later why. */ add_action( 'pre_user_query', 'maor_twitter_help_main' ); /* Create a new WP_User_Query object, limit recordset to 10 */ $wp_user_search = new WP_User_Query( array( 'number' => 12, 'role' => 'Author' //I just wanted to check the Authors ) ); /* Make sure to remove this action since it may affect other user queries around the site. */ remove_action( 'pre_user_query', 'maor_twitter_help_main' ); /* Get them users! */ $users = $wp_user_search->get_results(); return $users; } } add_filter('sul_users_results', 'kia_meta_search'); function maor_twitter_help_main( $query ) { global $wpdb; $search = ( isset($_GET['as']) ) ? sanitize_text_field($_GET['as']) : false ; if ( $search ){ /* The display_name value you're looking to match */ $display_name = $search; /* Search can either be for an exact match or a partial match */ if ( $use_like_syntax = true ) { $query->query_where .= $wpdb->prepare( " AND $wpdb->users.display_name LIKE %s", '%' . like_escape( $display_name ) . '%' ); } else { $query->query_where .= $wpdb->prepare( " AND $wpdb->users.display_name = %s", $display_name ); } } }
Forum: Plugins
In reply to: [Simple User Listing] New FilterI forgot this line of code after the new filter code:
if ( empty ($users) ) { $users = $sul_users->get_results(); }
if this is not present there would be no results without a search.