Soo I just made a simple search page. Its working! But i wanted to filter the results. The query that i wanted to make its like, it will search by the name of the articles and filter it, soo it only appears the articles from the category X (By ID).

This is my form:

<form action="<?php get_bloginfo('url') ?>" id="searchform" method="get">
            <input type="text" value="" name="search" id="search" />
            <input type="submit" id="searchsubmit" value="Search" />

This is my query:

query_posts( array(
             's' => $_REQUEST[ 'search' ],
             'category' => '',
             'paged' => $paged

EDIT: Im kinda stuck on the category part. I know it doesnt work if it stays there empty.

Attempt 1

Tried to equal the category id and use it as a query

query_posts( array(
             's' => $_REQUEST[ 'search' ],
             the_category_ID() => '42',
             'paged' => $paged

Try this code

$args = array(
     's' => $_REQUEST[ 'search' ],
     'cat' => 'category_id',
     'paged' => $paged
// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
    //inside the loop

// Reset Post Data


Hope this help

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.