Support » Fixing WordPress » Custom taxonomy query giving wrong result (PHP ver dependancy?)

  • Hi.

    I’m trying to query custom taxonomies for a custom post type. And I’m trying to make it an “OR” relation.

    I’m making a music archive, where I want to list other discs from the same artist. Sometimes there are discs with 2 different artists, so I’d like to list the discs from these artists on the same list. So I made a query like :

    $args = array (
            'post_type' => 'disc',
            'tax_query' => array (
                'relation' => 'OR',
                array ( 'taxonomy' => 'disc_artist',
                       'field' => 'slug',
                       'terms' => $artistnames[0]
                      ),
                array ( 'taxonomy' => 'disc_artist',
                       'field' => 'slug',
                       'terms' => $artistnames[1]
                      ),
            ));
        $the_query = new WP_Query($args);

    This works on my localhost (XAMPP), but when uploaded on my hosted website, it just doesn’t work. The result query is a list of 10 most recent custom posts, which have nothing to do with the terms I made query with. (I tried with different fields like term_id and name. Same result..)

    So I’m guessing, if it has something to do with PHP versions or SQL versions? My hosted server is UTF-8 (PHP5.3, MySQL5.x), and my XAMPP has PHP5.5.15. (Sorry, I have no idea where to find the SQL version of XAMPP.)

    If somebody knows how to make the right query on my website, I’ll be thankful for any kind of help.

Viewing 1 replies (of 1 total)
  • I tried the same thing with get_posts(), which behaved the same. ‘operator’=>’OR’, ‘relation’=>’OR’ did the same thing.

    I then somehow achieved what I wanted with query_posts(), which was like :

    $args = array('post_type'=>'disc', 'posts_per_page'=>6, ''=>$artistname, 'order'=>'DESC');
    query_posts( $args );

    and $artistname is a string where I joined A and B by a comma.

    So, this works on both localhost and hosted server. But I’ve heard that it’d be better not to use query_posts() if possible. I’d like to go with WP_Query or get_posts() if it’s possible, especially because I don’t really get what really matters and I’ll have to include this query twice per post. Any solution? (Or… is it safe enough to use query_posts() in this case??)

Viewing 1 replies (of 1 total)
  • The topic ‘Custom taxonomy query giving wrong result (PHP ver dependancy?)’ is closed to new replies.