[wp-trac] [WordPress Trac] #42469: WP_Query found_posts inconsistent data type.
WordPress Trac
noreply at wordpress.org
Thu Nov 9 14:18:50 UTC 2017
#42469: WP_Query found_posts inconsistent data type.
--------------------------+------------------------------
Reporter: PressLabs | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by birgire):
Thanks for the patch @PressLabs.
The database query returns a string, so this seems a valid concern.
I checked the other query classes and they also convert it to integer.
In {{{WP_Comment_Query}}} we see:
{{{
$found_comments_query = apply_filters( 'found_comments_query', 'SELECT
FOUND_ROWS()', $this );
$this->found_comments = (int) $wpdb->get_var( $found_comments_query );
}}}
and in {{{WP_Site_Query}}} we have:
{{{
$found_sites_query = apply_filters( 'found_sites_query', 'SELECT
FOUND_ROWS()', $this );
$this->found_sites = (int) $wpdb->get_var( $found_sites_query );
}}}
Similarly in {{{WP_User_Query}}}:
{{{
$this->total_users = (int) $wpdb->get_var( apply_filters(
'found_users_query', 'SELECT FOUND_ROWS()' ) );
}}}
I would suggest making it more readable and change:
{{{
$this->found_posts = intval( $wpdb->get_var( apply_filters_ref_array(
'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ) );
}}}
to
{{{
$found_posts_query = apply_filters_ref_array( 'found_posts_query', array(
'SELECT FOUND_ROWS()', &$this ) );
$this->found_posts = (int) $wpdb->get_var( $found_posts_query );
}}}
in {{{WP_Query}}}.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42469#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list