0
<?php
while($row2 = mysql_fetch_array($result)){

$object_id = $row2['object_id'];
$sql ="select term_taxonomy_id from wp_term_relationships where object_id =
$object_id";
$results = mysql_query($sql);

while($row3 = mysql_fetch_array($results)){

    $term_taxonomy_id1[] = $row3['term_taxonomy_id']."<br/>";

  }

}
print_r($term_taxonomy_id1);
?>

上記のコードを使用した後、配列に term_taxonomy_id をフェッチしました

    Array (
    [0] => 249
    [1] => 250
    [2] => 251
    [3] => 252
    [4] => 250
    [5] => 251
    [6] => 254
    ) 

term_id を取得したい (カテゴリー、ブランド、およびデザイナーの分割タクソノミー列に基づく)

これはテーブル構造です

表: wp_term_taxonomy

ここに画像の説明を入力

私はそのような出力が必要です

       Array
    (
    [category] => Array
      (
      [0] => 177
      [1] => 179
      )
    [brand] => Array
      (
      [0] => 176
      )
    [designer] => Array
      (
      [0] => 175
      [1] => 180
      )
    ) 
4

2 に答える 2

0
<?php
while($row2 = mysql_fetch_array($result)){

      $object_id = $row2['object_id'];

      $sql ="select term.term_taxonomy_id,wp.term_id from wp_term_relationships as term  inner join wp_term_taxonomy as wp ON term.term_taxonomy_id=wp.term_taxonomy_id where object_id = $object_id";

      $results = mysql_query($sql);

      $i=0;
     while($row3 = mysql_fetch_array($results)){
         $term_taxonomy_id1[$i] = $row3['term_taxonomy_id'];

         $res_term_id[$i] = $row3['term_id'];

       }
}
于 2012-07-18T12:30:50.777 に答える
0

term_taxonomy_idの必要性を理解していないため、これが正しいかどうかはわかりませんが、それでも役立つ場合は:

$data=array();
while($row3=mysql_fetch_assoc($result)){
  $taxonomy=$row3['taxonomy'];
  $sql2="select term_id from wp_term_relationships where taxonomy=$taxonomy";
  $res=mysql_query($sql2);
  while($row4=mysql_fetch_assoc($res)){
    $tab[]=$row4['term_id'];
  }
  $data[$taxonomy]=$tab;
}

これは最善ではありません。パフォーマンスを向上させるために JOIN プロシージャを使用することはできますが、機能するはずです。

于 2012-07-18T12:43:51.730 に答える