0
私はWP_Queryを使用して、メタデータの結果を使用するカスタムポストタイプの投稿を取得しています。すべてが私のクエリでうまくいきます。しかし、このクエリの後、私はデータベースから他のメタ値を取得することはできません。
これは、カスタムフィールドの値を取得するために私のヘルパー関数です:
function my_page_get_custom_field($value) {
global $post;
$custom_field = get_post_meta($post->ID, $value, true);
if (!empty($custom_field))
return is_array($custom_field) ? stripslashes_deep($custom_field) : stripslashes(wp_kses_decode_entities($custom_field));
return false;
}
は、ここに私のクエリです:
$sliderArgs = array(
'posts_per_page' => -1,
'post_type' => 'slider',
);
$slider = new WP_Query($sliderArgs);
if ($slider->have_posts()) {
?>
<select name="slider" id="slider">
$selectedSlide = my_page_get_custom_field('slider');
while($slider->have_posts()){
$slider->the_post();
$slideID = get_the_ID();
?><option value="<?php echo $slideID; ?>" <?php selected($selectedSlide, $slideID, true); ?>><?php the_title(); ?></option><?php
}
wp_reset_postdata(); ?>
</select>
}
そして、これは空を返す私の他のカスタムフィールドである(データベースに値があります変更しようとすると、管理者の入力値には表示されません):
<input type="text" name="meta_title" id="meta_title" value="<?php echo my_page_get_custom_field('meta_title'); ?>">
私はこれがあなたの問題だと思う: 'posts_per_page' => -1。代わりに 'posts_per_page' => 1を試すことができますか? –
@ LajosArpad残念ながら、それはすべての投稿を照会するためのものです。 :) –