私はElliot Condonの優れた高度なカスタムフィールドを使用して設定された3つの異なる変数に基づいて3つの特定のIDを取得するカスタムWordPressクエリを作成しようとしています。複数の可変ポストIDを持つWordpressクエリ
私は私の変数を設定するためにこれを使用しています:
<?php
$post1 = get_field('post_1');
$post2 = get_field('post_2');
$post3 = get_field('post_3');
?>
をそして、私はこのようなカスタムクエリにこれらの変数を渡したい:
<?php
$post_list = array($post1, $post2, $post3);
foreach($post_list as $post_id) :
query_posts('p='.$post_id);
while (have_posts()) : the_post();
// echo the post
endwhile;
wp_reset_query();
endforeach;
?>
しかし、上記のようではありません。作業して壊れたページになります。誰でもどのように修正するためのアイデアがありますか?私は明らかに変数をクエリに間違って渡していますが、それを修正する方法を理解することはできません。
EDIT - SOLUTION
はここで働いて更新されたブロックです。 DACrosbyに大きな感謝!カスタムポストタイプのクエリを実行しているので、$args
でどのタイプを指定する必要がありました。
<div class="row">
<?php
$post1 = get_field('related_1');
$post2 = get_field('related_2');
$post3 = get_field('related_3');
$args = array(
'post__in' => array($post1, $post2, $post3),
'post_type' => 'work'
);
$the_query = new WP_Query($args);
?>
<?php if ($the_query->have_posts()): ?>
<ul class="case-studies cf fade-in fade-in-3">
<!-- Basic Projects -->
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<?php
//Get Featured Image URL
$feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
//Get Project Categories
$terms = get_the_terms($post->ID, 'type');
?>
<li class="case-study">
<img src="<?php echo $feat_image; ?>" alt="<?php the_title(); ?>">
<a href="<?php the_permalink(); ?>" class="cs-hover">
<div class="col-table cs-text">
<div class="col-tcell">
<span><?php the_title(); ?></span>
<span class="divider"></span>
<span><?php the_field('description'); ?></span>
<?php if(get_field('services')): ?>
<ul class="tags">
<?php while(has_sub_field('services')): ?>
<li><?php the_sub_field('service'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<span class="text-link">View Project</span>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
私はこれを実装しようとしましたが、それでも動作させることはできません。私は上に私の完全なコードブロックを追加...多分私は間違っている場所にスポットすることができますか?私は本当にあなたの助けに感謝します! –
すぐに間違っているとは思わない。何か間違いはありますか?あなたのサーバーのerror_logファイルをチェックするか、[WordPressでエラーを表示する](https://codex.wordpress.org/Debugging_in_WordPress) – DACrosby
ログにエラーが表示されず、ページの残りの部分が正常に読み込まれています。しかし出力されているのは '