Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Or" in conditional logics #839

Closed
hellor0bot opened this issue Apr 7, 2016 · 15 comments
Closed

"Or" in conditional logics #839

hellor0bot opened this issue Apr 7, 2016 · 15 comments
Labels
Milestone

Comments

@hellor0bot
Copy link

Is it possible to add "or" operator in the conditional logics?

See the syntax from WP_Query:

    'tax_query' => array(
        'relation' => 'OR',
        array(
            'taxonomy' => 'movie_genre',
            'field'    => 'slug',
            'terms'    => array( 'action', 'comedy' ),
        ),
        array(
            'taxonomy' => 'actor',
            'field'    => 'term_id',
            'terms'    => array( 103, 115, 206 ),
            'operator' => 'NOT IN',
        ),
    ),

Please correct me if I'm wrong, but there's no thing like relation in Kirki now and it accepts only AND by default.

@rahulv3a
Copy link

rahulv3a commented Apr 7, 2016

If you are talking about required, Kirki uses AND operator.

But there is a workaround to use OR operator, see #769.

@hellor0bot
Copy link
Author

The workaround is quite dirty though. For example I have select 1 and select 2, both have 10 options each, with this workaround I would have to specify 18 (!) conditions instead of two.

@rahulv3a
Copy link

rahulv3a commented Apr 7, 2016

I agree. I hope they address this in the future versions.

@aristath
Copy link
Contributor

aristath commented Apr 8, 2016

There are plans to do that in a future release, just not yet.

The syntax that will probably be used will be like this:

'required' => array(
    array(
        array(
        ),
        // OR
        array(
        ),
    ),
    // AND
    array(
    ),
),

Right now there are simply more important issues to deal with so this will have to wait for a while...

Marking as a feature request 👍

@aristath aristath added this to the 3.0 milestone Apr 8, 2016
@hellor0bot
Copy link
Author

Thanks, @aristath!

@aristath
Copy link
Contributor

aristath commented May 3, 2016

This is now implemented in the develop branch, I'd really appreciate it if you guys could test it.

Example:

'active_callback' => array(
    array(
        array(
            'setting'  => 'setting_1',
            'operator' => '==',
            'value'    => true,
        ),
        array(
            'setting'  => 'setting_2',
            'operator' => '==',
            'value'    => true,
        ),
    ),
    array(
        'setting'  => 'setting_3',
        'operator' => '==',
        'value'    => true,
    ),
),

The above can be translated like this:
( ( if setting_1 == true OR setting_2 == true ) AND setting_3 == true )

@aristath
Copy link
Contributor

aristath commented May 3, 2016

In other words, active_callback is an array.
each item in that array is evaluated using AND.
However, if that item is an array of requirements, then these are evaluated using OR.

@guillaumemolter
Copy link
Contributor

Ahah...I was ready it and it wasn't making sence. Better now :-)

@aristath
Copy link
Contributor

aristath commented May 3, 2016

LOL yeah, there was a typo that I edited. ;)

@aristath
Copy link
Contributor

aristath commented May 3, 2016

@guillaumemolter do you perhaps have any ideas on how to make the syntax easier to understand?
I just found this structure pretty versatile... This way we're not limited to either AND or OR and we can combine them.

@guillaumemolter
Copy link
Contributor

Hmmm...I think it's pretty clear this way. Personally I may have implemented the WP_Meta_Query syntax but not because it is easier or easier to understand but simply because I would assume it's the "WordPress way" to do it. In other words I think it is great like that so unless someones complain leave it like that :-).

@rahulv3a
Copy link

rahulv3a commented May 5, 2016

Just tested this, works like a charm 👍

@hellor0bot
Copy link
Author

Thanks, it's working. But the syntax really bothers me. Don't think it's flexible enough.

I suppose it must be AND inside the item array and OR between items.

Just the opposite:

( ( if setting_1 == true AND setting_2 == true ) OR setting_3 == true )

Otherwise we can't group conditions:

( ( if setting_1 == true AND setting_2 == true ) OR ( if setting_3 == false AND setting_4 == false ) )

@aristath
Copy link
Contributor

aristath commented May 9, 2016

I suppose it must be AND inside the item array and OR between items.

I agree, but unfortunately we can't do that because it would break things for everyone that was using it before the change.
Maintaining backwards-compatibility is a bitch, I know...

@hellor0bot
Copy link
Author

hellor0bot commented May 9, 2016

Sometimes breaking changes are unavoidable. That's why they're breaking ;)

Anyway, I think it's better to change it now, before Kirki gains even more users. However it's your product and I can't really complain. It's so great and saved me a lot of time, really. Thanks a lot, really.

@aristath aristath modified the milestones: 3.0, 2.4.0 Dec 10, 2016
@hellor0bot hellor0bot mentioned this issue Dec 13, 2016
@aristath aristath modified the milestones: 2.4.0, 3.0 Mar 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants