diff --git a/assets/js/autosuggest.js b/assets/js/autosuggest.js index db8928ba7d..0d5eeaacf4 100644 --- a/assets/js/autosuggest.js +++ b/assets/js/autosuggest.js @@ -575,6 +575,27 @@ function init() { } }; + /** + * Get the searched post types from the search form. + * + * @param {HTMLFormElement} form - form containing the search input field + * @returns {Array} - post types + * @since 3.6.0 + */ + function getPostTypesFromForm(form) { + const data = new FormData(form); + + if (data.has('post_type')) { + return data.getAll('post_type').slice(-1); + } + + if (data.has('post_type[]')) { + return data.getAll('post_type[]'); + } + + return []; + } + /** * Calls the ajax request, and outputs the results. * Called by the handleKeyup callback, debounced. @@ -584,6 +605,7 @@ function init() { const fetchResults = async (input) => { const searchText = input.value; const placeholder = 'ep_autosuggest_placeholder'; + const postTypes = getPostTypesFromForm(input.form); // retrieves the PHP-genereated query to pass to ElasticSearch const queryJSON = getJsonQuery(); @@ -595,7 +617,21 @@ function init() { if (searchText.length >= 2) { setFormIsLoading(true, input); - const query = buildSearchQuery(searchText, placeholder, queryJSON); + let query = buildSearchQuery(searchText, placeholder, queryJSON); + + if (postTypes.length > 0) { + query = JSON.parse(query); + + if (typeof query.post_filter.bool.must !== 'undefined') { + query.post_filter.bool.must.push({ + terms: { + 'post_type.raw': postTypes, + }, + }); + } + + query = JSON.stringify(query); + } // fetch the results const response = await esSearch(query, searchText); diff --git a/dist/js/admin-script.min.js b/dist/js/admin-script.min.js index 120d1d127b..08313e9bd0 100644 --- a/dist/js/admin-script.min.js +++ b/dist/js/admin-script.min.js @@ -1 +1 @@ -!function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"===typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)r.d(e,o,function(n){return t[n]}.bind(null,o));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="",r(r.s=347)}({10:function(t,n,r){var e=r(9),o=r(11),i=r(20);t.exports=e?function(t,n,r){return o.f(t,n,i(1,r))}:function(t,n,r){return t[n]=r,t}},11:function(t,n,r){var e=r(9),o=r(40),i=r(6),u=r(26),c=Object.defineProperty;n.f=e?c:function(t,n,r){if(i(t),n=u(n,!0),i(r),o)try{return c(t,n,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported");return"value"in r&&(t[n]=r.value),t}},12:function(t,n,r){var e=r(19),o=Math.min;t.exports=function(t){return t>0?o(e(t),9007199254740991):0}},120:function(t,n,r){"use strict";var e=r(8),o=r(32).find,i=r(92),u=!0;"find"in[]&&Array(1).find((function(){u=!1})),e({target:"Array",proto:!0,forced:u},{find:function(t){return o(this,t,arguments.length>1?arguments[1]:void 0)}}),i("find")},13:function(t,n,r){var e=r(28),o=r(15);t.exports=function(t){return e(o(t))}},14:function(t,n){var r={}.toString;t.exports=function(t){return r.call(t).slice(8,-1)}},15:function(t,n){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},17:function(t,n,r){var e=r(15);t.exports=function(t){return Object(e(t))}},18:function(t,n,r){var e=r(64),o=r(2),i=function(t){return"function"==typeof t?t:void 0};t.exports=function(t,n){return arguments.length<2?i(e[t])||i(o[t]):e[t]&&e[t][n]||o[t]&&o[t][n]}},19:function(t,n){var r=Math.ceil,e=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?e:r)(t)}},2:function(t,n,r){(function(n){var r=function(t){return t&&t.Math==Math&&t};t.exports=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof n&&n)||function(){return this}()||Function("return this")()}).call(this,r(52))},20:function(t,n){t.exports=function(t,n){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:n}}},21:function(t,n,r){var e=r(2),o=r(10),i=r(7),u=r(23),c=r(34),f=r(42),a=f.get,s=f.enforce,p=String(String).split("String");(t.exports=function(t,n,r,c){var f,a=!!c&&!!c.unsafe,l=!!c&&!!c.enumerable,v=!!c&&!!c.noTargetGet;"function"==typeof r&&("string"!=typeof n||i(r,"name")||o(r,"name",n),(f=s(r)).source||(f.source=p.join("string"==typeof n?n:""))),t!==e?(a?!v&&t[n]&&(l=!0):delete t[n],l?t[n]=r:o(t,n,r)):l?t[n]=r:u(n,r)})(Function.prototype,"toString",(function(){return"function"==typeof this&&a(this).source||c(this)}))},23:function(t,n,r){var e=r(2),o=r(10);t.exports=function(t,n){try{o(e,t,n)}catch(r){e[t]=n}return n}},24:function(t,n,r){var e=r(2),o=r(23),i=e["__core-js_shared__"]||o("__core-js_shared__",{});t.exports=i},25:function(t,n){t.exports={}},26:function(t,n,r){var e=r(5);t.exports=function(t,n){if(!e(t))return t;var r,o;if(n&&"function"==typeof(r=t.toString)&&!e(o=r.call(t)))return o;if("function"==typeof(r=t.valueOf)&&!e(o=r.call(t)))return o;if(!n&&"function"==typeof(r=t.toString)&&!e(o=r.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},27:function(t,n){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},28:function(t,n,r){var e=r(3),o=r(14),i="".split;t.exports=e((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==o(t)?i.call(t,""):Object(t)}:Object},29:function(t,n,r){var e,o,i=r(2),u=r(60),c=i.process,f=c&&c.versions,a=f&&f.v8;a?o=(e=a.split("."))[0]+e[1]:u&&(!(e=u.match(/Edge\/(\d+)/))||e[1]>=74)&&(e=u.match(/Chrome\/(\d+)/))&&(o=e[1]),t.exports=o&&+o},3:function(t,n){t.exports=function(t){try{return!!t()}catch(t){return!0}}},30:function(t,n,r){var e=r(9),o=r(58),i=r(20),u=r(13),c=r(26),f=r(7),a=r(40),s=Object.getOwnPropertyDescriptor;n.f=e?s:function(t,n){if(t=u(t),n=c(n,!0),a)try{return s(t,n)}catch(t){}if(f(t,n))return i(!o.f.call(t,n),t[n])}},31:function(t,n,r){var e=r(35),o=r(36),i=e("keys");t.exports=function(t){return i[t]||(i[t]=o(t))}},32:function(t,n,r){var e=r(50),o=r(28),i=r(17),u=r(12),c=r(46),f=[].push,a=function(t){var n=1==t,r=2==t,a=3==t,s=4==t,p=6==t,l=7==t,v=5==t||p;return function(y,d,h,g){for(var x,b,m=i(y),w=o(m),j=e(d,h,3),O=u(w.length),S=0,P=g||c,_=n?P(y,O):r||l?P(y,0):void 0;O>S;S++)if((v||S in w)&&(b=j(x=w[S],S,m),t))if(n)_[S]=b;else if(b)switch(t){case 3:return!0;case 5:return x;case 6:return S;case 2:f.call(_,x)}else switch(t){case 4:return!1;case 7:f.call(_,x)}return p?-1:a||s?s:_}};t.exports={forEach:a(0),map:a(1),filter:a(2),some:a(3),every:a(4),find:a(5),findIndex:a(6),filterOut:a(7)}},34:function(t,n,r){var e=r(24),o=Function.toString;"function"!=typeof e.inspectSource&&(e.inspectSource=function(t){return o.call(t)}),t.exports=e.inspectSource},347:function(t,n,r){"use strict";r.r(n);r(120);var e=window,o=e.epAdmin,i=e.ajaxurl;jQuery(".notice").on("click",".notice-dismiss",(function(t){var n=t.delegateTarget.getAttribute("data-ep-notice");n&&jQuery.ajax({method:"post",data:{nonce:o.nonce,action:"ep_notice_dismiss",notice:n},url:i})})),jQuery(".weighting-settings input[type=range]").on("input",(function(){var t=jQuery(this);t.prev("label").find(".weighting-value").text(t.val())})),jQuery(".weighting-settings .searchable input[type=checkbox]").change((function(){var t=jQuery(this).parent().next(".weighting").find("input[type=range]"),n=t.prev("label").find(".weighting-value");t.prop("disabled",!this.checked);var r=this.checked?t.val():"0";n.text(r)}))},35:function(t,n,r){var e=r(43),o=r(24);(t.exports=function(t,n){return o[t]||(o[t]=void 0!==n?n:{})})("versions",[]).push({version:"3.9.1",mode:e?"pure":"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})},36:function(t,n){var r=0,e=Math.random();t.exports=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++r+e).toString(36)}},37:function(t,n){t.exports=function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t}},38:function(t,n,r){var e=r(14);t.exports=Array.isArray||function(t){return"Array"==e(t)}},39:function(t,n,r){var e=r(54),o=r(29),i=r(3);t.exports=!!Object.getOwnPropertySymbols&&!i((function(){return!Symbol.sham&&(e?38===o:o>37&&o<41)}))},4:function(t,n,r){var e=r(2),o=r(35),i=r(7),u=r(36),c=r(39),f=r(66),a=o("wks"),s=e.Symbol,p=f?s:s&&s.withoutSetter||u;t.exports=function(t){return i(a,t)&&(c||"string"==typeof a[t])||(c&&i(s,t)?a[t]=s[t]:a[t]=p("Symbol."+t)),a[t]}},40:function(t,n,r){var e=r(9),o=r(3),i=r(41);t.exports=!e&&!o((function(){return 7!=Object.defineProperty(i("div"),"a",{get:function(){return 7}}).a}))},41:function(t,n,r){var e=r(2),o=r(5),i=e.document,u=o(i)&&o(i.createElement);t.exports=function(t){return u?i.createElement(t):{}}},42:function(t,n,r){var e,o,i,u=r(69),c=r(2),f=r(5),a=r(10),s=r(7),p=r(24),l=r(31),v=r(25),y=c.WeakMap;if(u){var d=p.state||(p.state=new y),h=d.get,g=d.has,x=d.set;e=function(t,n){return n.facade=t,x.call(d,t,n),n},o=function(t){return h.call(d,t)||{}},i=function(t){return g.call(d,t)}}else{var b=l("state");v[b]=!0,e=function(t,n){return n.facade=t,a(t,b,n),n},o=function(t){return s(t,b)?t[b]:{}},i=function(t){return s(t,b)}}t.exports={set:e,get:o,has:i,enforce:function(t){return i(t)?o(t):e(t,{})},getterFor:function(t){return function(n){var r;if(!f(n)||(r=o(n)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return r}}}},43:function(t,n){t.exports=!1},44:function(t,n,r){var e=r(7),o=r(13),i=r(59).indexOf,u=r(25);t.exports=function(t,n){var r,c=o(t),f=0,a=[];for(r in c)!e(u,r)&&e(c,r)&&a.push(r);for(;n.length>f;)e(c,r=n[f++])&&(~i(a,r)||a.push(r));return a}},46:function(t,n,r){var e=r(5),o=r(38),i=r(4)("species");t.exports=function(t,n){var r;return o(t)&&("function"!=typeof(r=t.constructor)||r!==Array&&!o(r.prototype)?e(r)&&null===(r=r[i])&&(r=void 0):r=void 0),new(void 0===r?Array:r)(0===n?0:n)}},48:function(t,n,r){var e=r(44),o=r(27).concat("length","prototype");n.f=Object.getOwnPropertyNames||function(t){return e(t,o)}},49:function(t,n,r){var e=r(19),o=Math.max,i=Math.min;t.exports=function(t,n){var r=e(t);return r<0?o(r+n,0):i(r,n)}},5:function(t,n){t.exports=function(t){return"object"===typeof t?null!==t:"function"===typeof t}},50:function(t,n,r){var e=r(37);t.exports=function(t,n,r){if(e(t),void 0===n)return t;switch(r){case 0:return function(){return t.call(n)};case 1:return function(r){return t.call(n,r)};case 2:return function(r,e){return t.call(n,r,e)};case 3:return function(r,e,o){return t.call(n,r,e,o)}}return function(){return t.apply(n,arguments)}}},51:function(t,n,r){var e=r(44),o=r(27);t.exports=Object.keys||function(t){return e(t,o)}},52:function(t,n){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"===typeof window&&(r=window)}t.exports=r},53:function(t,n,r){var e=r(3),o=/#|\.prototype\./,i=function(t,n){var r=c[u(t)];return r==a||r!=f&&("function"==typeof n?e(n):!!n)},u=i.normalize=function(t){return String(t).replace(o,".").toLowerCase()},c=i.data={},f=i.NATIVE="N",a=i.POLYFILL="P";t.exports=i},54:function(t,n,r){var e=r(14),o=r(2);t.exports="process"==e(o.process)},58:function(t,n,r){"use strict";var e={}.propertyIsEnumerable,o=Object.getOwnPropertyDescriptor,i=o&&!e.call({1:2},1);n.f=i?function(t){var n=o(this,t);return!!n&&n.enumerable}:e},59:function(t,n,r){var e=r(13),o=r(12),i=r(49),u=function(t){return function(n,r,u){var c,f=e(n),a=o(f.length),s=i(u,a);if(t&&r!=r){for(;a>s;)if((c=f[s++])!=c)return!0}else for(;a>s;s++)if((t||s in f)&&f[s]===r)return t||s||0;return!t&&-1}};t.exports={includes:u(!0),indexOf:u(!1)}},6:function(t,n,r){var e=r(5);t.exports=function(t){if(!e(t))throw TypeError(String(t)+" is not an object");return t}},60:function(t,n,r){var e=r(18);t.exports=e("navigator","userAgent")||""},61:function(t,n,r){var e,o=r(6),i=r(80),u=r(27),c=r(25),f=r(75),a=r(41),s=r(31),p=s("IE_PROTO"),l=function(){},v=function(t){return"