A
A
Alexey Nikolaev2015-01-20 18:10:00
CMS
Alexey Nikolaev, 2015-01-20 18:10:00

Why does a query with mutually exclusive parameters work?

Hello!
In one of the places in the theme code, WP found a snippet:

<?php
$args = array(
  'post_type' => 'post',
  'tax_query' => array(
    'relation' => 'OR',
    array(
      'taxonomy' => 'category',
      'field' => 'slug',
      'terms' => array( 'some-tag' )
    )		
  )
);

As you can see, the code should (the actual execution of the request follows) receive posts from the category whose slug matches some-tag . But there is no such category in the database (meaning the standard WP category), there is only a label with such a slug, and this query still works .
The question is - how can this be, perhaps I'm missing something? ..
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Vorotnev, 2015-01-23
@Heian

It is necessary to look at the SQL query itself, which turned out. I suspect that something like "if there are posts for this tax_query - return them, otherwise - standard results" because of the OR operator. I can be wrong, but debugging without the SQL query itself is unrealistic. Install the Query Monitor plugin - everything will be decided in a couple of minutes.

A
Alexander Bagirov, 2015-01-20
@alexbagirov

What is a "category in the database"?
If you mean columns, then WP probably has an extra. a handler that converts these parameters.

S
Sergey, 2015-01-21
@gangstarcj

Am I the only one seeing an array? where is the request?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question