Advanced Search

1

I'm trying to do an advanced search for a particular site. I have already created and the form is functional, which would be something like this:

The idea is that the "title" field look only in the post_title, which is the title of the product. The "Author" field has to look only at the value of the "author" attribute of the product. And so the rest of the fields.

I did some tests with the action 'pre_get_posts' but without interesting achievements.

In the form one of the fields I always call 's' to use the search because in the function I use if($query->is_search) {

I could not find an example that could give me a guide on how to resolve this point, if anyone can give me an idea I will be grateful.

    
asked by Armage 06.07.2016 в 00:06
source

1 answer

0

It seems that this is a question of making a query with nested subqueries if what you want is to obtain the filter in a single query.

Then, I would do it like this:

// Asignas las variables del $_POST
$autor = $_POST['autor']; 

// Filtras valores y demas medidas de seguridad

// Armas query

$query = 
"SELECT
 (SELECT titulo FROM tabla WHERE titulo= '$titulo') AS titulo, 
 (SELECT autor FROM tabla WHERE autor = '$autor') AS autor, 
 (SELECT contenido FROM tabla WHERE contenido= '$contenido') AS contenido, 
 (SELECT isbn FROM tabla WHERE isbn= '$isbn') AS isbn, 
 (SELECT categoria FROM tabla WHERE categoria= '$categoria') AS categoria, 
FROM
 tabla
WHERE
 fecha = '$fecha' ";

// Ejecutas 

You only substitute the names of your fields and the variables, keep in mind that they are all in quotation marks, if a column of your table is a numeric type, you remove it.

To test it you can do it in Phpmyadmin or in the platform that you are using.

Greetings.

    
answered by 10.11.2016 / 23:46
source