• Resolved flojdm

    (@flojdm)


    Hi there,

    I’m using admin columns to filter a custom post type “document” and I need to implement an “OR” condition when combining multiple filters for “users” who have an attachment with a document. Currently, when I apply multiple user filters, it seems to apply an “AND” condition automatically, which doesn’t allow me to filter as needed.

    Best regards,

    • This topic was modified 5 months, 3 weeks ago by flojdm.
    • This topic was modified 5 months, 3 weeks ago by flojdm.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter flojdm

    (@flojdm)

    I just saw that someone had already asked this question and you said it wasn’t possible but please is there any way to do this ? Maybe with a filter for a specific column ?

    Thread Starter flojdm

    (@flojdm)

    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.
    Plugin Author Stefan van den Dungen Gronovius

    (@dungengronovius)

    Please, note that the forum on WordPress is not meant for support for our Pro version. You can send your request to [email protected]

    We don’t encourage to change the codebase of our plugin to make something work for your use case. At this moment, we don’t have the support for ‘OR’ with an available hook. To support that, it would require more than just changing the mentioned file.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.