WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
Different loops (5 posts)

  1. nudosunidos
    Member
    Posted 3 years ago #

    Hello! I Work about a month looking for a solution to this .., I tested with new WP plugins and Query, but I can not find a solution. If you can help me, thank you very much in advance, sincerely.

    Finally I opted for the plugin query multiple taxonomies, I filter 3 taxonomies, this works fine, but here's the problem, I show different loops and paginated sorting by 3 different date field.

    Example:

    QMT forms:
    TAX1: architecture, engineering, etc...
    TAX2: open, new, close
    TAX3: bydate1, bydate2, bydate3

    Sorting:

    architecture (or any this tax) + open (or any this tax) + bydate1 show all this selection sorted by date field A

    architecture (or any this tax) + open (or any this tax) + bydate2 show all this selection sorted by date field B

    architecture (or any this tax) + open (or any this tax) + bydate3 show all this selection sorted by date field C

    It's possible?

    PD: Sorry my bad English..

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Yes, by hooking into 'posts_orderby' filter. Something like this:

    function alter_orderby( $orderby_sql ) {
      $query = qmt_get_query(); // get the current tax query, as an associative array
    
      if ( !isset( $query['bydate'] ) )
        return $orderby_sql; // no term in the bydate tax selected
    
      if ( 'bydate1' == $query['bydate'] ) {
        $orderby_sql = '...'; // SQL for sorting by date field A
      }
      elseif ( 'bydate2' == $query['bydate'] ) {
        $orderby_sql = '...'; // SQL for sorting by date field B
      }
      elseif ( 'bydate3' == $query['bydate'] ) {
        $orderby_sql = '...'; // SQL for sorting by date field C
      }
    
      return $orderby_sql;
    }
    add_filter( 'posts_orderby', 'alter_orderby' );

    You can see the entire SQL query by using the Debug Bar plugin.

  3. nudosunidos
    Member
    Posted 3 years ago #

    :O Thank you! Now I try the loop with new WpQuery? these 3 date fields I have to compare with the current date ASC or DESC without breaking the page, i hope to get! This has been advanced for me...

  4. nudosunidos
    Member
    Posted 3 years ago #

    Scribu, I feel confused with this, but i don't know how to use this function, I do not understand what should be the loop. I'm sorry :( sincere thanks

  5. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    So, put the above code in functions.php or whatever, then just do a normal loop:

    while ( have_posts() ) : the_post();
    
    ...
    
    endwhile;

    If that's still too advanced for you, I suggest hiring someone (not me) to code it for you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic