[wp-hackers] Advanced Taxonomy Query Question

Nikola Nikolov nikolov.tmw at gmail.com
Wed May 14 07:43:05 UTC 2014


Hi Haluk,

1 - no it doesn't matter. As far as I'm aware, WordPress will type-juggle
it as necessary( so it will end-up as int(10) ), or it will just use it
as-is, since it's ending-up as a string anyway(in the MySQL query).

2 - that should not be a problem. Basically the difference is the
following:
 - When you use "=" operator, the part of the WHERE clause will look like
*slug='sourceX'*
 - When you use "IN" operator, it will look like *slug IN ('sourceX')*

Both of those are just fine, except for the second option(the way you do it
at the moment) will allow you to query for multiple terms in the future.

Hope that helps,
Nikola


On Wed, May 14, 2014 at 10:22 AM, Haluk Karamete <halukkaramete at gmail.com>wrote:

> In the following sample Advanced Tax. Query, I have 2 questions.
>
> 1. does the fact that posts_per_page is being sent in as 'string' ( as
> opposed to 'integer' ) makes a difference to WordPress?
>
> 2. please take a look at the branch dealing with the 'source' taxonomy, ( -
> the last one ). As you see there, the 'source' taxonomy has only one item
> to worry about and that is 'sourceX'. In a single term case like that, does
> the operator being set as 'IN' as opposed to being set as  'AND' makes a
> difference to WordPress?
>
> Sample Advanced Tax. Query
>
> Array
> (
>     [posts_per_page] => 10   <var_dump reports this as string>
>     [order] => DESC
>     [tax_query] => Array
>         (
>             [relation] => AND
>             [0] => Array
>                 (
>                     [taxonomy] => category
>                     [field] => slug
>                     [terms] => Array
>                         (
>                             [0] => cat1
>                             [1] => cat2
>                         )
>
>                     [operator] => AND
>                     [include_children] =>
>                 )
>
>             [1] => Array
>                 (
>                     [taxonomy] => post_tag
>                     [field] => slug
>                     [terms] => Array
>                         (
>                             [0] => tag 1
>                             [1] => tag2
>                             [2] => tag3
>                         )
>
>                     [operator] => IN
>                     [include_children] => 1
>                 )
>
>             [2] => Array
>                 (
>                     [taxonomy] => source
>                     [field] => slug
>                     [terms] => Array
>                         (
>                             [0] => sourceX
>                         )
>
>                     [operator] => IN     <on a single term, does IN or
> AND matters?>
>                     [include_children] => 1
>                 )
>
>         )
>
> )
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list