【问题标题】:WordPress custom query pagination with datepicker problem带有日期选择器问题的WordPress自定义查询分页
【发布时间】:2018-12-18 09:49:50
【问题描述】:

我有一个包含 3 个字段的搜索表单,其中一个是 JQuery UI datepicker
和一个自定义 wp_Query 来显示搜索结果
和wordpress分页功能
搜索结果显示正确
但是,当我尝试转到下一页时,我认为它也会正确显示结果
但 url 看起来不正确 网址如下所示:

​/page/2/?search=run&date#038;date

在控制台出现以下错误:

jquery.js?ver=1.12.4:2 Uncaught Error: Syntax error, unrecognized expression: #038;date
at Function.fa.error (jquery.js?ver=1.12.4:2)
at fa.tokenize (jquery.js?ver=1.12.4:2)
at fa.select (jquery.js?ver=1.12.4:2)
at Function.fa (jquery.js?ver=1.12.4:2)
at Function.a.find (jquery-migrate.min.js?ver=1.4.1:2)
at n.fn.init.find (jquery.js?ver=1.12.4:2)
at n.fn.init.a.fn.find (jquery-migrate.min.js?ver=1.4.1:2)
at a.fn.init.n.fn.init (jquery.js?ver=1.12.4:2)
at new a.fn.init (jquery-migrate.min.js?ver=1.4.1:2)
at n (jquery.js?ver=1.12.4:2)

当我从表单中删除日期字段时,它工作得很好。

这是与日期相关的JQuery部分

    jQuery(function() {
jQuery( ".datepicker" ).datepicker({
  changeMonth: true,
  changeYear: true,
  showButtonPanel: true,
  dateFormat:'m-yy',
  onClose: function(dateText, inst){
    jQuery(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth,1));
    var selected_month = inst.selectedMonth+1;
    var month = jQuery("#ui-datepicker-div .ui-datepicker-month :selected").val();
    var year = jQuery("#ui-datepicker-div .ui-datepicker-year :selected").val();
    var full_date = jQuery(".datepicker").datepicker("getDate");
    var myElement = document.getElementById("datepicker");
    console.log(myElement);
    }
  });
});

知道如何从网址中删除“#038;date”部分吗?

我希望当用户转到搜索结果的第二页时,该 url 看起来像这样
/page/2/?search=运行&日期
而不是这个
/page/2/?search=run&date#038;date

看来这个问题与日期选择器无关 我仍然不知道为什么以及如何解决它,但是这个问题没有正确描述问题

【问题讨论】:

    标签: wordpress datepicker pagination jquery-ui-datepicker search-form


    【解决方案1】:

    在这里,我将分享有关如何从 url 中删除“#038;date”部分的语法

    alert(url.substring(0, url.indexOf('?')));
    

    另外,这里有一个基本的解决方法:

    //the URL ( decode it just for GOOD practice)
    var someRandomUrl = decodeURI("http://example.com?modal=name");
    
    //here we do the splitting
    var splittedParts = someRandomUrl.split("?");
    
    // the first part of the array will be URL you will require
    var theURL = splittedParts[0];
    
    // the second part of the array will be the Query String
    var theQuery = splittedParts[1];
    alert(theURL);

    希望对你有用。

    【讨论】:

    • 我不想删除整个查询字符串,我想要的是:当用户转到搜索结果的第二页时,url 看起来像这样:::: /page/ 2/?search=run&date 而不是 this:::: /page/2/?search=run&date#038;date
    猜你喜欢
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 2017-12-16
    • 2021-07-25
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    相关资源
    最近更新 更多