07-27-2023, 09:25 AM
I am trying to write a new query function using `WP_Query` object.
I created a new template file and put the followings:
$query_args = array(
'post_type' => 'page',
'post_parent=41',
);
// The Featured Posts query.
$results = new WP_Query($query_args);
But whatever arguments I use, the query does not change. It looks as if the query is already initialized and creating a new `WP_Query` does not have any effect on the existing query.
The only wordpress function called before my code is `get_header()` which does not include any call to `WP_Query` or `query_posts`.
I put the following line to find out what the actual sql query is:
echo $GLOBALS['wp_query']->request;
The actual sql query is:
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
This query does not change when I change my `$query_args`.
I wonder when the global variable `$wp_query` is initialized and what should I do to use my own query?
I created a new template file and put the followings:
$query_args = array(
'post_type' => 'page',
'post_parent=41',
);
// The Featured Posts query.
$results = new WP_Query($query_args);
But whatever arguments I use, the query does not change. It looks as if the query is already initialized and creating a new `WP_Query` does not have any effect on the existing query.
The only wordpress function called before my code is `get_header()` which does not include any call to `WP_Query` or `query_posts`.
I put the following line to find out what the actual sql query is:
echo $GLOBALS['wp_query']->request;
The actual sql query is:
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
This query does not change when I change my `$query_args`.
I wonder when the global variable `$wp_query` is initialized and what should I do to use my own query?