Solved

Wordpress sorting by multiple custom fields

Posted on 2014-01-30
1
403 Views
Last Modified: 2014-02-18
Hi,
I have a website which has the following code in, this worked up until 3.8 but now does not, can anyone tell me why or offer another equally simply way to achieve this. Put simply I have two custom fields, the first of which could be null therefor I need to show the rest but sort primarily by the first field.

$args = array(
'post_type' => 'course',
'provider' => $term,
'posts_per_page' => 50,
'paged' => $paged,
'meta_key' => 'course_startdate',
'meta_compare' => '>=',
'orderby' => 'meta_value',
'meta_value' => $date,
'order' => 'ASC',
'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'course_startdate',
            'value' => $date,
            'compare' => '>='
       ),
        array(
            'key' => 'course_trainingtype',
            'value' => $date,
            'compare' => '>='
        )
));
query_posts($args);

Open in new window


Many thanks
0
Comment
Question by:ScorchD
1 Comment
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 500 total points
ID: 39833014
Write your query string separately in a variable and run it
<?php

 $querystr = "
    SELECT $wpdb->posts.* 
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
  .....................
.....................
..............
 ";

 $yourvariablename= $wpdb->get_results($querystr, OBJECT);
 
 ?>

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question