WordPressで関連記事を表示したいのですが、使用しているテーマの関連記事の条件が「同じカテゴリー」のみです。
以下の条件を追加したいです。
①カスタムタクソノミー”location”が同じ記事
②カスタムフィールド"end-date"(Y/m/d)が今日以降のもの
使用テーマのsingle.phpに上記の条件を加える形で以下のコードに変更しました。
①は反映されているのですが、②が反映されません。間違っているところが分かりましたらお教えいただけますと幸いです。
何卒よろしくお願いいたします。
if ( $dp_options['show_related_post'] ) : $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'post__not_in' => array( $post->ID ), 'posts_per_page' => $dp_options['related_post_num'], 'orderby' => 'rand' ); $categories = get_the_category(); if ( $categories ) : $category_ids = array(); foreach( $categories as $category ) : if ( !empty( $category->term_id ) ) : $category_ids[] = $category->term_id; endif; endforeach; $locations = get_the_terms( $post->ID, 'location' ); if ( $locations ) : $location_ids = array(); foreach( $locations as $location ) : if ( !empty( $location->term_id ) ) : $location_ids[] = $location->term_id; endif; endforeach; endif; if ( $category_ids ) : $args['tax_query'][] = array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $category_ids, 'operator' => 'IN' ), array( 'taxonomy' => 'location', //カスタムタクソノミー 'field' => 'term_id', 'terms' => $location_ids, 'operator' => 'IN' ), array( 'meta_key' => 'end-date', //カスタムフィールドの名前 'meta_value' => date('Y/m/d'), 'meta_compare' => '>=', 'meta_type' => 'DATE' ) ); endif; endif; $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : ?>

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。