0

カスタムタイプの投稿を作成しました。カテゴリとタグに含まれるすべての投稿を取得したいと考えています。残念ながら、なぜ 1 つの投稿しか返されないのかわかりません (少なくとも 3 つまたは 4 つあるはずです)。

これは私のコードです:

$tag = $_GET["tag"];
$cat = $_GET["cat"];

$args = array(
    'post_type' => 'post_product',
    'post_status' => 'publish',
    'numberposts' => -1,
    array(
        array(
            'taxonomy' => 'cating'
        ),
        array(
            'taxonomy' => 'tagging')
    )
);

$custom_query = new WP_Query( $args );

if ( $custom_query->have_posts() ):

    while ( $custom_query->have_posts() ) :
        $custom_query->the_post();

        $product_terms = wp_get_object_terms(get_the_ID(), 'cating');
        $product_terms_tag = wp_get_object_terms(get_the_ID(), 'tagging');

        if(!empty($product_terms) && !empty($product_terms_tag)){
            if(!is_wp_error( $product_terms ) && !is_wp_error( $product_terms_tag )){

                foreach($product_terms as $term){
                    if(strcmp($term->name, $cat) == 0) {

                        foreach($product_terms_tag as $term_tag){
                            if(strcmp($term_tag->name, $tag) == 0) {

                                // display here

                            }
                        }
                    }
                }
            }
        }
    }
}

それらの条件を尊重する投稿であるため、なぜ私が1つの投稿しか取得しないのか、または何も取得しないのか、誰にもわかりません。

ありがとうございました。

4

2 に答える 2

0

タクソノミー クエリ パラメータの形式が正しくありません。$_GETまた、変数も使用していません。

を通じて用語 ID を取得していると仮定すると、次の$_GETようになります。

$args = array(
    'post_type' => 'post_product',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'tax_query' => array(
        'relation' => 'AND',
         array(
            'taxonomy' => 'tagging',
            'field' => 'id',
            'terms' => (int) $tag
        ),
        array(
            'taxonomy' => 'cating',
            'field' => 'id',
            'terms' => (int) $cat
        )
    )
);
于 2013-11-09T13:26:02.180 に答える