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

Multiple taxonomies relation not working #131

Closed
bernhardgessler opened this Issue Oct 24, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@bernhardgessler

bernhardgessler commented Oct 24, 2016

First of all: Thanks for this amazing plugin!
Now to my issue: I'm unable to combine multiple taxonomies with an OR relation. I've been looking into the code and could fix it for my purposes but I'm not sure how good this solution is as I'm not very firm with PHP nor with WP.

The issue is in the following code:

        if( $more_tax_queries ):
            $tax_relation = 'AND';
            if( isset( $original_atts['tax_relation'] ) && in_array( $original_atts['tax_relation'], array( 'AND', 'OR' ) ) )
                $tax_relation = $original_atts['tax_relation'];
            $args['tax_query']['relation'] = $tax_relation;
        endif;

        $args = array_merge( $args, $tax_args );

If I log the $args variable before the array_merge, it contains the relation:

Array
(
    [category_name] => 
    [order] => desc
    [orderby] => date
    [post_type] => Array
        (
            [0] => post
        )

    [posts_per_page] => 10
    [tag] => 
    [post_status] => Array
        (
            [0] => publish
        )

    [tax_query] => Array
        (
            [relation] => OR
        )
)

Afterwards not anymore:

Array
(
    [category_name] => 
    [order] => desc
    [orderby] => date
    [post_type] => Array
        (
            [0] => post
        )

    [posts_per_page] => 10
    [tag] => 
    [post_status] => Array
        (
            [0] => publish
        )

    [tax_query] => Array
        (
            [0] => Array
                (
                    [taxonomy] => post_program
                    [field] => slug
                    [terms] => Array
                        (
                            [0] => someslug
                        )

                    [operator] => IN
                    [include_children] => 1
                )

            [1] => Array
                (
                    [taxonomy] => post_location
                    [field] => slug
                    [terms] => Array
                        (
                            [0] => someotherslug
                        )

                    [operator] => IN
                    [include_children] => 1
                )
        )
)

Using array_merge_recursive instead solves the issue.

@billerickson

This comment has been minimized.

Show comment
Hide comment
@billerickson

billerickson Jan 1, 2017

Owner

Thanks for the patch! This will be included in the next release

Owner

billerickson commented Jan 1, 2017

Thanks for the patch! This will be included in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment