0

i have a custom search which will have 3 inputs (dropdowns) , the html code of the form is ready and will use GET in url , now the remaining part is using values from url to run query. Parameters will be : category, tag and custom field So far i have managed getting the value in url , quering it get post by custom post type category using this code :

$args=array(
  'post_type' => 'tyre',
  'post_status' => 'publish',
  'tax_query' => array(
        array(
            'taxonomy' => 'tyre-category',
            'field' => 'ID', //can be set to ID
            'terms' => $catid //if field is ID you can reference by cat/term number
        )
        )
);

Till here i managed to pull out the items in the category of custom post.
Now the remaining part will be check two custom fields and if the value matches as in parameter in url then display. how will be able to do that i am not sure how to modify the loop for that.

EDIT!

I have Managed 90% of it by using meta_query code below :

'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => 'size',
            'value' => $size,
            'compare' => '='
        ),
        array(
            'key' => 'terrain',
            'value' => $terrain,
            'compare' => '='
        )
    )  

Now the only problematic part is extracting and check value from a custom field called size, as it can have comma seperated multiple sizes.

Help is Appreciated! Thanks and Regards

1 Answer 1

1

Ok i manged to create the solution by finding that LIKE condition can be used in meta query. so here is the final code..

$args=array(
  'post_type' => 'tyre',
  'post_status' => 'publish',
  'tax_query' => array(
        array(
            'taxonomy' => 'tyre-category',
            'field' => 'ID', //can be set to ID
            'tag' => 'ID', //can be set to ID
            'terms' => $catid //if field is ID you can reference by cat/term number
        )
        ),
        'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => 'size',
            'value' => $size,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'terrain',
            'value' => $terrain,
            'compare' => '='
        )
    )
);

Hope it will be useful for someone :)
cheers
Ayaz Malik

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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