• Hello,

    I’m trying to filter and sort my results on multiple meta keys/values. Is this possible?

    Here’s my current set of args I tried to send to the function but they don’t appear to be working…

    $args = array(
           		'post_type' => 'workshop',
           		'post_status' => 'publish',
           		'ws-type' => $campsite,
           		'meta_query' => array(
           			array(
    					'key' =>  $csite.'-date-block',
    					'value' => $days[$d],
    					'type' => 'char',
    					'compare' => '='
    				),
    				array(
    					'key' =>  $csite.'-time-block',
    					'value' => $i,
    					'type' => 'numeric',
    					'compare' => '='
    				)
    			),
           		'orderby' => array(
           			array(
           				'meta_key' => $csite.'-date-block',
           				'order' => 'ASC'
           			),
           			array(
           				'meta_key' => $csite.'-time-block',
           				'order' => 'ASC'
           			)
           		), //'key',
           		//'sort' => 'ASC',
           		'posts_per_page' => 100
           	);

    This was just a shot in the dark, so I’m guessing the arrays I put in the orderby section are invalid. Is there a way to make this work with WP_Query though or do I need to use a different method? Also, the second field I’m sorting on is a time field, so I’m wondering if the system is going to have an issue with that. I may need to change the type of data being held in that field.

    I’m currently on 3.1 but trying to upgrade to 3.3.1 if I can get the host to upgrade the php version on the server.

    Thanks,
    Wil

Viewing 1 replies (of 1 total)
  • 1. I am not sure what the ‘ws-type’ => $campsite is, but that is not a valid arg.

    2. Orderby can only accept a value as a string.

    Also, the second field I’m sorting on is a time field

    Do you mean a Unix timestamp or some other format?

    See WP_Query docs.

    Custom queries based on Custom Fields should work on 3.1 but I would definitely hope your host upgrades php.

Viewing 1 replies (of 1 total)
  • The topic ‘Multiple meta_key sorts with WP_Query?’ is closed to new replies.