After searching a lot I’ve found a way to do it but encountering an issue with the meta query generation in the query.php
file within the admin-column-pro/Classes
directory. Despite my efforts to modify the code, I’m facing difficulties with combining multiple entity IDs in the meta query.
<?php
namespace ACP;
use AC\Registerable;
use ACP\Query\Bindings;
use LogicException;
abstract class Query implements Registerable
{
/**
* @var Bindings[]
*/
protected $bindings;
/**
* @param Bindings[] $bindings
*/
public function __construct(array $bindings)
{
$this->bindings = $bindings;
$this->validate_bindings();
}
/**
* @throws LogicException
*/
private function validate_bindings(): void
{
foreach ($this->bindings as $bindings) {
if ( ! $bindings instanceof Bindings) {
throw new LogicException('Expected Bindings object.');
}
}
}
protected function get_meta_query(): array
{
$meta_query = [];
$entities_ids = [];
foreach ($this->bindings as $binding) {
$args = $binding->get_meta_query();
if ($args["key"] == "entity_id") {
$entity_id = (int) unserialize($args["value"]);
$entities_ids[] = $entity_id;
} else {
$meta_query[] = $binding->get_meta_query();
}
}
$meta_query = array_filter($meta_query);
if ($entities_ids) {
$entity_meta_queries = [];
foreach ($entities_ids as $entity_id) {
$entity_meta_queries[] = [
'key' => 'entity_id',
'value' => $entity_id,
'compare' => 'LIKE',
];
}
$meta_query[] = [
'relation' => 'OR',
$entity_meta_queries,
];
}
$meta_query[] = [
'relation' => 'AND',
];
return $meta_query;
}
}
Then query :
array(3) { [0]=> array(4) { [“key”]=> string(6) “source” [“value”]=> string(6) “import” [“compare”]=> string(1) “=” [“type”]=> string(4) “CHAR” } [1]=> array(2) { [“relation”]=> string(2) “OR” [0]=> array(2) { [0]=> array(3) { [“key”]=> string(20) “entity_id” [“value”]=> int(3206) [“compare”]=> string(4) “LIKE” } [1]=> array(3) { [“key”]=> string(20) “entity_id” [“value”]=> int(2991) [“compare”]=> string(4) “LIKE” } } } [2]=> array(1) { [“relation”]=> string(3) “AND” } } array(1) { [0]=> array(1) { [“relation”]=> string(3) “AND” } }
While the meta query seems to be correct individually, it doesn’t work as expected when combining multiple entity IDs. However, it works fine when I only use one entity ID.
Any idea on how to fix this?
Thank you for your attention to this matter.
-
This reply was modified 5 months, 2 weeks ago by flojdm.