Compare commits
No commits in common. "bdba8664dae22e39d83012f9fce99b25b267fdf2" and "76dc12f2ac64704a4bfd264e572aadc49e30e8b7" have entirely different histories.
bdba8664da
...
76dc12f2ac
|
@ -38,8 +38,8 @@ if ( ! function_exists( 'my_pre_get_posts_associats' ) ){
|
|||
// bail early if not main query or plugin $the_query_associat
|
||||
// - allows custom code / plugins to continue working
|
||||
if( !$query->is_main_query() ) return;
|
||||
$query->set( 'posts_per_page', -1);
|
||||
//$query->set( 'relation', 'AND');
|
||||
|
||||
|
||||
|
||||
// loop over filters
|
||||
foreach( $GLOBALS['my_query_filters_associat'] as $key => $fieldname)
|
||||
|
@ -48,31 +48,36 @@ if ( ! function_exists( 'my_pre_get_posts_associats' ) ){
|
|||
if( empty($_GET[ $fieldname ]) ) { continue; }
|
||||
|
||||
// get original meta query
|
||||
$meta_query = []; //avoids infinite nesting
|
||||
$meta_query = [];
|
||||
$meta_query[] = $query->get('meta_query');
|
||||
$meta_query[] = array('relation' => 'OR');
|
||||
|
||||
// get the values for this filter
|
||||
// eg: http://domain.tdl/associat/?xxp_associat_target=autonoma,entitat-publica
|
||||
$filtervalues= explode(',', $_GET[ $fieldname ]);
|
||||
|
||||
// loop retreived values from checkboxes and filter them
|
||||
// loop retreived values from checkboxes and filter them with REGEXP
|
||||
// http://domain.tdl/associat/?xxp_associat_target=autonoma&xxp_associat_field=circi
|
||||
// http://domain.tdl/associat/?xxp_associat_target=autonoma,entitat-publica&xxp_associat_field=dansa
|
||||
foreach( $filtervalues as $filteredvalue )
|
||||
{
|
||||
// they are array based fields
|
||||
// https://barn2.com/blog/querying-posts-by-custom-field-acf/#array-based-fields
|
||||
$strippedvalue = sprintf( '^%1$s$|s:%2$u:"%1$s";', $filteredvalue, strlen( $filteredvalue ) );
|
||||
|
||||
// add our meta query to the original meta queries
|
||||
$meta_query['relation'] = 'OR';
|
||||
// add our meta query to the original meta queries
|
||||
$meta_query[] = array(
|
||||
'key' => $fieldname,
|
||||
'value' => $filteredvalue,
|
||||
'compare' => 'LIKE'
|
||||
array(
|
||||
'key' => $fieldname,
|
||||
'value' => $strippedvalue,
|
||||
'compare' => 'REGEXP',
|
||||
),
|
||||
);
|
||||
}
|
||||
// update the meta query arguments
|
||||
$query->set('meta_query', $meta_query);
|
||||
//$query->set('relation', 'AND');
|
||||
// update the meta query arguments
|
||||
$query->set('meta_query', $meta_query);
|
||||
}
|
||||
//echo '<pre>' . var_export($query, true) . '</pre>';
|
||||
//echo '<pre>' . print_r($query,true) . '</pre>';
|
||||
|
||||
//always return
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* Plugin URI: https://git.hangar.org/xarxaprod/xarxaprod-wp-plugin
|
||||
* Description: Different needs for the Xarxaprod.cat Wordpress theme needs. Adds support for: SVG.
|
||||
* Date: 2023 12 29
|
||||
* Version: 1.3.0
|
||||
* Version: 1.1.0
|
||||
* Author: jorge - vitrubio.net
|
||||
* Author URI: https://vitrubio.net/
|
||||
* License: GPL 3.0
|
||||
|
|
Loading…
Reference in New Issue