-1

I am using headwaythemes to create my website. I like to custimize the ORDER-BY.

This is the code I found in the file.

'order-by' => array(
    'type' => 'select',
    'name' => 'order-by',
    'label' => 'Order By',
    'tooltip' => '',
'options' => array(
    'date' => 'Date',
    'title' => 'Title',
    'rand' => 'Random',
    'comment_count' => 'Comment Count',
    'ID' => 'ID',
    'meta_value_num' => 'Custom' // my code
    )
),

I added this line and it shows up in the select box. But nothing happens cause like http://codex.wordpress.org/Class_Reference/WP_Query there is missing the 'meta_key=keyname' this must also be present.

How do I make it present?

I tried an array( oderby => meta_value_num, meta_key => images_likes ) => 'Custom' // my code but this does not work, too.

Can some tell me how to add the meta_key?

Pieter Goosen
  • 9,768
  • 5
  • 35
  • 55
DenisCGN
  • 397
  • 1
  • 4
  • 17

1 Answers1

0

I'm not fimiliar with the theme you are using, but this should be the general approach (Hope you've done your customizations in a child theme :-))

You will need to alter the query arguments. I think you have a couple of choices here

  • Create extra text fields for the meta key, meta value and comparison operator

  • Hardcode the meta_query if there is no need for this to be dynamic

For both options you would want to first check if the orderby=meta_value_num option is selected. I don't know if this is simple checkboxes or a dropdown, but you should be able to write a conditional statement to check whether or not this option is selected or not.

If you go with option bullet point 1 above, you can also have an extra check to test if you have values entered into the three text fields.

As I already said, you will need to alter the query arguments, and you also would need to place the current query arguments into your conditional statement, something like this, in English:

if( orderby=meta_value_num is selected plus additional check if bullet point 1 option) {

    $args = array(
        'post_type'  => 'product',
        'orderby' => 'OPTION KEY FOR THIS',
        'meta_key' => 'color',
        'meta_query' => array(
            array(
                 'key'     => 'color',
                 'value'   => 'blue',
            ),
        ),
    );

}else{

    //DEFAULT THEME QUERY ARGUMENTS

}
Pieter Goosen
  • 9,768
  • 5
  • 35
  • 55