さて、今月までに投稿を表示したいだけのクライアントがいます。私はいくつかのバリエーションを試しましたが、どれもうまくいきませんでした。これが私が今いるところです。任意の助けは大歓迎です!
<?php
$current_year = date('Y');
$current_month = date('m');
$args = array(
'year' => $current_year,
'monthnum' => $current_month
);
$custom_query = new WP_Query('$args');
if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post();
// The following determines what the post format is and shows the correct file accordingly
$format = get_post_format();
get_template_part( 'includes/post-formats/'.$format );
if($format == '')
get_template_part( 'includes/post-formats/standard' );
endwhile; else:
?>
$current_month = date('m');
は$current_month = date('n');
であるべきです
WP_Queryオブジェクトのページを参照してください。
codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters
"month_num"は、 "01-12"からではなく、 "1-12"からのintです。変数が現在設定されている方法では、$ current_monthに先行ゼロがあります。先行ゼロなしで月を返すという単純な変更でこれが解決すると思います。私は、この不適切にフォーマットされた引数が原因でクエリがエラーになっていると思います。また、上のコメントで述べたように、WP_Queryの "$ args"を引用符で囲まないようにしてください。