0

不動産Wordpressブログです。私は連鎖した3選択ボックスに取り組んでいます。

私はそのほとんどを理解しましたが、どうすればよいか理解できないのは、カテゴリと価格帯に基づいてベッドルームの数のメタデータのみを返すように投稿をクエリすることです.

カテゴリに基づいて選択するように機能しています:

    SELECT DISTINCT meta_value
FROM wp_posts
LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
LEFT JOIN wp_term_taxonomy ON 
(wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
WHERE 1
AND wp_term_taxonomy.term_id IN ($_POST[id])
AND meta_key = '_lwi_bedroomsCount'
GROUP BY wp_posts.ID
ORDER BY meta_value ASC

このクエリに追加する必要があるのは、これらの引数の価格範囲です。

    $args['meta_query'][] = array(
'key'   => '_lwi_price',
'value' => array(strval($pricerange[0]),strval($pricerange[1])),
'compare' => 'BETWEEN',
'type' => 'numeric', );

これを SQL ステートメントに追加するにはどうすればよいですか?

注: $_POST[id] はカテゴリ ID です。

4

1 に答える 1

1
    ### get term id by Category name ####

    $sql = "SELECT * "
           ."   FROM wp_b9la0x2_terms wp_b9la0x2_terms "
           ."   WHERE (wp_b9la0x2_terms.name = '".$_REQUEST['category_name']."');";   

    $result = $conn->query($sql) or die($conn->error);
    $row = $result->fetch_assoc();

    #### get all post by category and also sub category ###

    $sql = "SELECT wp_b9la0x2_posts.ID,"
            . "       wp_b9la0x2_posts.post_title, "
            . "       wp_b9la0x2_posts.post_content, "
            . "       wp_b9la0x2_posts.post_excerpt, "
            . "       wp_b9la0x2_posts.post_date, "
            . "       wp_b9la0x2_posts.post_date_gmt, "
            . "       wp_b9la0x2_posts.post_modified, "
            . "       wp_b9la0x2_posts.post_modified_gmt, "
            . "       wp_b9la0x2_posts.guid, "
            . "       wp_b9la0x2_term_taxonomy.description, "
            . "       wp_b9la0x2_terms.name, "
            . "       wp_b9la0x2_posts.post_author, "
            . "       wp_b9la0x2_users.display_name as author_name "
            . "  FROM wp_b9la0x2_terms "
            . "  LEFT JOIN wp_b9la0x2_term_taxonomy wp_b9la0x2_term_taxonomy "
            ."          ON wp_b9la0x2_terms.term_id = wp_b9la0x2_term_taxonomy.term_id "
            ."   LEFT JOIN wp_b9la0x2_term_relationships wp_b9la0x2_term_relationships "
            ."          ON wp_b9la0x2_term_taxonomy.term_taxonomy_id = wp_b9la0x2_term_relationships.term_taxonomy_id "
            ."   LEFT JOIN wp_b9la0x2_posts wp_b9la0x2_posts"
            ."           ON wp_b9la0x2_term_relationships.object_id = wp_b9la0x2_posts.ID "
            ."   LEFT JOIN wp_b9la0x2_users wp_b9la0x2_users"
            ."           ON wp_b9la0x2_users.ID = wp_b9la0x2_posts.post_author "
            ."  WHERE (wp_b9la0x2_term_taxonomy.term_id = '".$row['term_id']."' OR `parent` = '".$row['term_id']."')"
            ."   AND (wp_b9la0x2_posts.post_status = 'publish')"
            ."   AND (wp_b9la0x2_posts.post_type = 'post')"
            . "  GROUP BY  wp_b9la0x2_posts.ID"
            . "  ORDER BY wp_b9la0x2_posts.post_date DESC";
    $result = $conn->query($sql) or die($conn->error);
    $res = array();

    while($row = $result->fetch_assoc()) {
        $test = array();
        foreach($row as $key => $val){
            $test[$key] = utf8_encode($val);
        }
       $res[] = $test;
    }
    echo json_encode($res);
于 2014-12-04T21:54:00.343 に答える