プロが教えるわが家の防犯対策術!

front-page.phpに設置している年月プルダウンPHPとarchive.phpのSQLを連結させたいのですがどうすればよいでしょうか?
$date_query = $pos;としたのですが上手くいきませんでした。

※該当コード
<div class="widget">
<h4 class="monthly-archive-title">月別アーカイブ</h4>

<?php
// 月別アーカイブリストを取得する
$monthly_archives = wp_get_archives(
$args = array(
'type' => 'monthly',
'show_post_count' => true,
'before' => '',
'after' => ',',
'echo' => 0,
));
$monthly_archives = explode(',', $monthly_archives); //配列化
array_pop($monthly_archives); //末尾の空白要素を削除

// 年別アーカイブリストを取得する
$yearly_archives = wp_get_archives(
$args = array(
'type' => 'yearly',
'format' => 'custom',
'before' => '',
'after' => ',',
'echo' => 0,
));
$yearly_archives = explode(',', $yearly_archives); //配列化
array_pop($yearly_archives); //末尾の空白要素を削除

$this_year = (string)idate('Y'); //現在の年を、4桁の文字列で取得

// HTMLとして出力するコードの記述部分
// ここから
$out = '<ul class="archive-list">';

foreach ($yearly_archives as $year) {
$the_year = substr($year,-8,4); // 「年」を表す部分のみ抽出する

if ($the_year === $this_year): // 今年だったら
$out .= '<li class="year acv_open current">' . $the_year;
$out .= '<ul class="month-archive-list">';
else: // それ以外の年の場合
$out .= '<li class="year">' . $the_year;
$out .= '<ul class="month-archive-list">';
endif;

foreach ($monthly_archives as $month) {
//月毎アーカイブの文字列中に、ターゲットとなる年が含まれているか
$pos = strpos($month, $the_year);

// 含まれている限り、li要素を出力
if ($pos !== false): // 該当する文字列が含まれているときは、その位置が返ってくるので、!==falseという判定文を使用
$out .= $month;
endif;
}
$out .= '</ul>'; // 閉じる <ul class="month-archive-list">
}
$out .= '</li>'; // 閉じる <li class="year">
$out .= '</ul>'; // 閉じる <ul class="archive-list">
// ここまで

// HTMLの出力
echo $out;
?>
</div>

※該当ファイル
https://wandbox.org/permlink/NYmE0RGsheAohj82

※参考サイト
https://cosybench.com/customize-wp-archives-look/

A 回答 (1件)

こうには出来ないですか?


シングルクォートで囲わないと数値として認識してしまうかも知れません
AND (post.post_date LIKE %s OR post.post_modified LIKE %s )

AND (post.post_date LIKE '%s' OR post.post_modified LIKE '%s' )
    • good
    • 1
この回答へのお礼

アドバイスありがとうございます。

お礼日時:2022/07/12 13:13

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!