Solved

Wordpress sorting by multiple custom fields

Posted on 2014-01-30
1
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML loaded in a form with dropdown 6 56
Code not executing correctly. 3 44
Undefined variable with $_POST in PHP 5 40
replacate wordpress websites 3 24
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

751 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