1

I am trying to use $wp_query->tax_query right out of the box as tax_query parameter, however I cannot work this out. The parameters for my new WP_Query is actually the same as the default query of the archive page I am in. I can not, however, use the default query since I am using a custom template for my post items.

Currently I define my tax_query this way:

array('tax_query' => $wp_query->tax_query)

Which is properly merged with the rest of my query, leaving this as the whole query:

Array
(
    [post-type] => am-curso
    [pagination] => 1
    [tags] => 
    [order-by] => title
    [order] => asc
    [tax_query] => WP_Tax_Query Object
        (
            [queries] => Array
                (
                    [0] => Array
                        (
                            [taxonomy] => am-course-category
                            [terms] => Array
                                (
                                    [0] => cursos-de-atualizacao
                                )

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

                )

            [relation] => AND
            [table_aliases:protected] => Array
                (
                    [0] => am_4_term_relationships
                )

            [queried_terms] => Array
                (
                    [am-course-category] => Array
                        (
                            [terms] => Array
                                (
                                    [0] => cursos-de-atualizacao
                                )

                            [field] => slug
                        )

                )

            [primary_table] => am_4_posts
            [primary_id_column] => ID
        )

)            

How can I get the query out of the WP_Tax_Query object? If I go down to queries like so: $wp_query->tax_query->queries[0], I still doesn't work.

I believe it might work if get the array in queries property and merge one layer above at tax_query. However I don't want to do this manually if there may be any already built-in way (which I seem not to be able to find anywhere).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.