WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Queries in one loop (custom fields) (1 post)

  1. Tailzip
    Member
    Posted 1 year ago #

    Hello,

    I have, on my category.php page, some filters to sort out results.
    In this example, I want to sort "Expositions" by these terms : 'date', 'zip_code','subcategory'.

    I made links like this :

    <a href="<?php echo add_query_arg(array('date' => 'now')); ?>">Now</a>, so I have this URL : .../expositions/?date=now

    To sort out by 'date', I use this arguments for my custom query :

    $date_args = array('meta_query' => array(
    'relation'=>'AND',
    array(
     'key' => 'date_start',
     'value' => date('Y m d'),
     'compare' => '<=',
     'type' => 'CHAR'),
    array(
     'key' => 'date_end',
     'value' => date('Y m d'),
     'compare' => '>=',
     'type' => 'CHAR'
    )));

    Then I merge my args :

    $args = array_merge( $wp_query->query, $date_args );
    query_posts($args);

    This works fine, but I'm trying to "mix" terms to sort results, I get into trouble...

    To sort out by 'zone', I use this arguments for my custom query :

    $zone_args = array('meta_query' => array(
    array(
    'key' => 'code_postal',
    'value' => $listeZones['paris_c'],
    'compare' => 'IN',
    'type' => 'numeric'
    ))
    );

    I'm looking for a solution to mix both custom queries. Because if my URL parameters are "?date=now&zone=paris_center", I want ONLY posts that match both criterias.

    I don't know if I'm clear...sorry for my bad english.

    Thanks for help ! :)

Topic Closed

This topic has been closed to new replies.

About this Topic