Solved

Wordpress sorting by multiple custom fields

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now