0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

wordpress 一覧出力でカスタムフィールドを条件にする

Posted at

一覧の出力って、カテゴリとか投稿タイプだけかと思っていたのですが、カスタムフィールドも可能なんですね。
知らんかった。

以下はquery_postsを使用しており、(ほんとはダメなの分かってるけど)
「statusというカスタムフィールドがfinish以外またはtodayというカスタムフィールドが空白以外の時」の記述。

$args = array(
'meta_query' => array(array(
                            'key' => 'status',
                            'value' => 'finish',
                            'compare' => '!='
                        ),
						array(
                            'key' => 'today',
                            'value' => '',
                            'compare' => '!='
                        ),
						'relation'=>'OR'
					),

);

条件を増やす場合は、array()を追加していけば良い。relationはANDとORが可能。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?