gpt4 book ai didi

用户元数据的 Ajax 分页

转载 作者:行者123 更新时间:2023-12-02 15:38:30 25 4
gpt4 key购买 nike

如果我的脚本搜索 user 依赖于用户元数据,如何在 AJAX 中设置分页链接。分页工作正常,但问题是分页链接不起作用。有人可以帮我弄清楚如何正确设置分页链接吗?

这是我的 AJAX 脚本:

function nanny_search_ajax1() {
$search_in = $_POST['search_in'];
$search_type = $_POST['search_type'];
$start_date = $_POST['start_date'];
$keyword = $_POST['keyword'];


if($search_in=='nanny'){
$search_in ='interested';
}
else{
$search_in ='lookgin';
}

$start_value = $start_date;
$start_compare = '=';


$nanny_result = '';
$nanny_error = '';


$number = 2;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ($paged - 1) * $number;

$args = array(
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'user_start',
'value' => $start_value,
'compare' => $start_compare
)
),
'offset'=>$offset,
'number'=>$number,
);


$users = get_users();
$query = get_users($args);
$total_users = count($users);
$total_query = count($query);
$total_pages = intval($total_users / $number) + 1;


$query = get_users($args);



if (!empty($query)) {
foreach ($query as $user) {
$profile_picture = wp_get_attachment_url(get_user_meta($user->ID, 'be_custom_avatar', true));
$profile_picture = get_avatar($user->ID, 100);
if($search_in=='nanny'){
$interested = get_user_meta($user->ID, 'interested', true);
}
else{
$interested = get_user_meta($user->ID, 'lookgin', true);
}

$user_date = get_user_meta($user->ID, 'user_start', true);
$aboutme = get_user_meta($user->ID, 'aboutme', true);
$user_link = get_author_posts_url($user->ID);

$nanny_result .= "<div class='nanny-babysiter-box'>";

if ($profile_picture != '') {
$nanny_result .="<div class='nanny-babysiter-box-img'>$profile_picture</div>";
}

$nanny_result .="<div class='user-icons'><ul><li><a href='#'><i class='fa fa-circle-o'></i></a></li><li><a href='#'><i class='fa fa-envelope-o'></i></a></li><li><a href='#'><i class='fa fa-star'></i></a></li></ul></div>";


$nanny_result .="<div class='user-details'><div class='details-sub search-title'><a target='_blank' href='$user_link'><span>$user->display_name</span></a></div>";




$nanny_result .="<div class='details-sub'>$interested</div>";


if ($user_date != '') {
$nanny_result .="<div class='details-sub'><span>Start Date : </span>$user_date</div>";
}
if ($aboutme != '') {
$nanny_result .="<div class='details-sub'><span>About Me : </span></div>";
}
$nanny_result .="</div>";
if ($aboutme != '') {
$nanny_result .="<div class='details-sub'>$aboutme</span></div>";
}

$nanny_result .="</div>";



}
if ($total_users > $total_query) {
$nanny_result.='<div id="pagination" class="clearfix">';
$nanny_result.='<span class="pages">Pages:</span>';
$current_page = max(1, get_query_var('paged'));
$nanny_result.= paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%/',
'current' => $current_page,
'total' => $total_pages,
'prev_next' => false,
'type' => 'list',
));
$nanny_result.= '</div>';
}
} else {
$nanny_error = '<div>Unfortunately at present there is no one matching your exact search criteria. You may like to consider other candidates.</div>';
}

echo json_encode(array("nanny_result" => $nanny_result, "nanny_error" => $nanny_error));
die;
}

add_action('wp_ajax_nopriv_nanny_search_ajax1', 'nanny_search_ajax1');
add_action('wp_ajax_nanny_search_ajax1', 'nanny_search_ajax1');

提前致谢。

最佳答案

我怀疑你的分页链接也应该是ajaxified,所以你可能会在javascript中使用像$('.prev-page').click(function(){ ... });这样的东西来定位它们。 。如果这是您的情况 - 您的分页链接会在页面加载和 DOM 解析后添加到 DOM,因此您的 click 事件不会绑定(bind)到目标元素。要将 javascript 事件绑定(bind)到动态创建/添加的 DOM 元素,请使用 on()delegate() 方法,例如 $('.prev-page')。 on('click', function(){ ... }).有关详细信息,请参阅文档。

关于用户元数据的 Ajax 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31775656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com