admin管理员组文章数量:1134243
I created this plugin to display a list of registered users with the Faciliator role. Displays the list in a table with name, country and avatar as titles. It works fine but the search box only considers the visible rows not the hidden pages due to pagination. Any help appreciated. This is the code.
<?php
function enqueue_plugin_scripts() {
wp_enqueue_style('facilitator-users-style', plugins_url('css/style.css', __FILE__));}
add_action('wp_enqueue_scripts', 'enqueue_plugin_scripts');
function display_facilitator_users_table() {
ob_start();
$users_per_page = 50;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ($paged - 1) * $users_per_page;
$args_all = array(
'role' => 'facilitator',
);
$all_facilitator_query = new WP_User_Query($args_all);
$args = array(
'role' => 'facilitator',
'number' => $users_per_page,
'offset' => $offset,
);
$facilitator_query = new WP_User_Query($args);
echo '<input type="text" id="user-search" placeholder="Search by name or country">';
echo '<table id="facilitator-users-table">';
echo '<thead><tr><th>Avatar</th><th>Name</th><th>Country</th></tr></thead>';
echo '<tbody>';
if (!empty($facilitator_query->results)) {
foreach ($facilitator_query->results as $user) {
$user_id = $user->ID;
$user_info = get_userdata($user_id);
$avatar = get_avatar($user_id, 60);
$name = $user_info->display_name;
$country = get_user_meta($user_id, 'user_country', true);
echo '<tr class="user-row ' . esc_attr($country) . '">';
echo '<td>' . $avatar . '</td>';
echo '<td><a href="' . get_author_posts_url($user_id) . '">' . esc_html($name) . '</a></td>';
echo '<td>' . esc_html($country) . '</td>';
echo '</tr>';
}
} else {
echo '<tr><td colspan="3">No facilitators found.</td></tr>';
}
echo '</tbody>';
echo '</table>';
echo '<div class="pagination">';
echo paginate_links(array(
'total' => ceil(count($all_facilitator_query->results) / $users_per_page),
'current' => $paged,
'prev_text' => '« Previous',
'next_text' => 'Next »',
));
echo '</div>';
return ob_get_clean();
}
add_shortcode('facilitator_users', 'display_facilitator_users_table');
function plugin_custom_script() {
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
var allUsers = $('.user-row');
$('#user-search').on('input', function () {
var searchValue = $(this).val().toLowerCase();
allUsers.hide();
allUsers.filter(function () {
return $(this).text().toLowerCase().indexOf(searchValue) !== -1;
}).show();
});
});
</script>
<?php
}
add_action('wp_footer', 'plugin_custom_script');
本文标签: pluginsSearch results not finding in paginated pages just in visible rows
版权声明:本文标题:plugins - Search results not finding in paginated pages just in visible rows 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736812202a1953939.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论