0

I'm trying to write a custom search function for my WordPress site. I'm using WP_Query and multiple arraylists.

Is it possible to order by search after taxonomy = pa_felg-bredde ?

Here is my code so far:

$the_query = new WP_Query( $args = array(
'posts_per_page' => 200,

    'tax_query' => array(
        'relation' => 'AND',


        array(
            'taxonomy' => 'pa_felg-bredde',
            'field' => 'slug',

          'terms' => array($f1, $f2, $f3, $f4, $f5, $f6, $f7, $f8, $f9, $f10)

        ),
        array(
            'taxonomy' => 'pa_diameter',
            'field' => 'slug',

            'terms' => array($ff1, $ff2, $ff3, $ff4, $ff5, $ff6, $ff7, $ff8, $ff9, $ff10)

        )


    )
));

$query = new WP_Query( $args );

I have now changed from taxonomis to custom field data on my products. Stil cant get the search result to be ordered when output to my website.
Anyone got a clue why that is?

    $the_query = new WP_Query( $args = array(
'post_type' => 'product',
'orderby' => 'cf_felgbredde',
'order' => 'DESC',
'relation' => 'AND',
'meta_query' => array(
array(<br>
'key' => ("cf_felgbredde"),
'value' => array($ff1, $ff2, $ff3, $ff4, $ff5, $ff6, $ff7, $ff8, $ff9, $ff10)
// 'compare' => 'LIKE'
),
array(
'key' => ("cf_hoyde"),
'value' => array($f1, $f2, $f3, $f4, $f5, $f6, $f7, $f8, $f9, $f10)
// 'compare' => 'LIKE'
), 
array(
'key' => ("cf_dimensjon"),
'value' => array($fff1, $fff2, $fff3, $fff4, $fff5, $fff6, $fff7, $fff8, $fff9, $fff10)
// 'compare' => 'LIKE'
),

)
));
5
  • If you want to order by a taxonomy value then you probably have a minor flaw in your design imo. Maybe pa_felg-bredde should have been set as a post_meta-field?
    – windyjonas
    Sep 23, 2014 at 8:05
  • This is a search for certain car wheels. pa_felg-bredde is a attribute on the product that contains wheel width (example: 15,16,16,17) So its not possible to create a custom search on a product attribute and the order by the size?
    – boomdrak
    Sep 23, 2014 at 8:13
  • yes it is, if you set the size as a custom field, not so easy if you set it as a taxonomy term.
    – windyjonas
    Sep 23, 2014 at 8:20
  • Okey, thanks for the tip. Im now re-importing all the products with product attributes as custom fields. Should it then be easy to use the ordreby in arrays to order the output?
    – boomdrak
    Sep 23, 2014 at 10:35
  • 1
    Please reformat and properly indent your code. It is a mess and unreadable. Oct 1, 2014 at 13:00

0

Your Answer

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

Browse other questions tagged or ask your own question.