Solved

Wordpress sorting by multiple custom fields

Posted on 2014-01-30
1
404 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. 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 : Go t…

830 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