最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - How can I use $wp_query->tax_query as tax_query parameter for a new WP_Query instatiation?

matteradmin7PV0评论

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).

Post a comment

comment list (0)

  1. No comments so far