Forums

[resolved] Wp_Query not rand (7 posts)

  1. StaLio
    Member
    Posted 1 year ago #

    Hi,

    I'm using WP 3.1 RC3 and when I'm trying to query with this code:

    <?php $portfolio = new WP_Query( array( 'tax_query' => array( array( 'taxonomy' => 'portfolio-options', 'field' => 'id', 'terms' => array( 20 ), 'operator' => 'NOT IN' )), 'post_type' => 'portfolio', 'orderby' => 'rand', 'order' => 'DESC', 'posts_per_page' => 10 )); ?>

    the posts aren't random, while when I'm removing
    'tax_query' => array( array( 'taxonomy' => 'portfolio-options', 'field' => 'id', 'terms' => array( 20 ), 'operator' => 'NOT IN' )),

    this part, which is copied from the codex, they will. Can someone say what I'm doing wrong?

  2. StaLio
    Member
    Posted 1 year ago #

    No one?

  3. Andrew Nacin
    WordPress Dev
    Posted 1 year ago #

    It looks like random doesn't work with tax_query.

  4. Dion Hulse (@dd32)
    WordPress Dev
    Posted 1 year ago #

    StaLio, Can you post the SQL that the code is generating?

    If you add this after the query, You should be able to locate the SQL:
    echo '<pre>';var_dump($portfolio);echo '</pre>';

  5. Austin Matzko
    Member
    Posted 1 year ago #

    I tried the same query, with custom post type and custom taxonomy, and it worked fine.

  6. StaLio
    Member
    Posted 1 year ago #

    Since I've updated to RC4, it works for me to, do you still need the SQL code?

  7. Andrew Nacin
    WordPress Dev
    Posted 1 year ago #

    Guess not. I don't think there were any changes between RC3 and RC4 that would affect this, but glad you got it sorted out.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.