オブジェクトを使用して新しいクエリ関数を作成しようとしていWP_Query
ます。
新しいテンプレートファイルを作成し、次のように配置しました。
$query_args = array(
'post_type' => 'page',
'post_parent=41',
);
// The Featured Posts query.
$results = new WP_Query($query_args);
しかし、どの引数を使用しても、クエリは変更されません。クエリはすでに初期化されているように見え、新しいクエリを作成しWP_Query
ても既存のクエリには影響しません。
私のコードの前に呼び出された唯一のワードプレス関数は、またはget_header()
への呼び出しを含まないものです。WP_Query
query_posts
次の行を入力して、実際のSQLクエリが何であるかを確認します。
echo $GLOBALS['wp_query']->request;
実際のSQLクエリは次のとおりです。
SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (wp_posts.ID = '14') AND wp_posts.post_type = 'page' ORDER BY wp_posts.post_date DESC
を変更しても、このクエリは変更されません$query_args
。
グローバル変数$wp_query
がいつ初期化されるのか、そして自分のクエリを使用するにはどうすればよいのでしょうか?