Opened 6 years ago
Closed 3 months ago
#42398 closed defect (bug) (invalid)
WP_Query with parameter post id 'p'=0 is not considered as a single post request
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7 |
Component: | Query | Keywords: | close |
Focuses: | Cc: |
Description
Hi there,
I'm trying to run a 'dummy' main WP query requesting only the post ID = 0 for performance purpose (all my requests are performed using AJAX with secondary extended WP queries)
However WP_Query does not detect a single post request adding SQL clauses like 'LIMIT'
In the class-wp-query.php file, the PHP test to set single post is
<?php } elseif ( $qv['p'] ) { $this->is_single = true;
that of course fails with 'p' = 0
Is that an expected behavior ?
I'm using the following code
<?php add_action('pre_get_posts', 'cb_pre_get_posts'); function cb_pre_get_posts($query){ $query->set('p', 0); }
Thanks in advance,
Change History (4)
#4
@
3 months ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
I agree with @dd32:
Ignoring requests for
p=0
seems like the expected behaviour to me, it's not a valid value for the parameter and thus isn't a single/singular request.
Closing this ticket as it is the expected behavior.
Note: See
TracTickets for help on using
tickets.
Ignoring requests for
p=0
seems like the expected behaviour to me, it's not a valid value for the parameter and thus isn't a single/singular request.If you wish to avoid the default WP_Query query, you can use the
posts_pre_query
filter (see #36687) - code below isn't tested