[wp-trac] [WordPress Trac] #49028: Provide functionality to suppress $wpdb query filter
WordPress Trac
noreply at wordpress.org
Sat Feb 8 13:27:59 UTC 2020
#49028: Provide functionality to suppress $wpdb query filter
-------------------------------+------------------------------
Reporter: aurovrata | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: trunk
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Comment (by aurovrata):
@johnbillion anyone reviewed this?
I have built the following hack in order to overcome this shortcoming,
{{{#!php
<?php
global $wpdb;
//I select postmetas that are specific to my plugin only (but some poorly
coded plugin still filters the query causing spurious results to be
returned).
$query =$wpdb->prepare("SELECT rpwc_pm.meta_id, rpwc_pm.post_id FROM
{$wpdb->postmeta} as rpwc_pm WHERE rpwc_pm.meta_key ='_rpwc2' AND
rpwc_pm.meta_value=%d", $term_id);
$match = "SELECT rpwc_pm.meta_id, rpwc_pm.post_id";
//so before I execute the query I register a filter with an anonymous fn
and put it last in the filter queue...
add_filter('query', function($q) use ($query, $match) {
if(strpos($q, $match)!==false) $q = $query;
return $q;
},PHP_INT_MAX);
$ranked_rows = $wpdb->get_results($query);
}}}
this is the only way to ensure I get the right results.
It would be so much simpler with a `suppress_filter` flag. Implementing a
flag is a very simple (few lines of code) fix in `wp-includes/wp-db.php`.
Can I make this change and submit it for review?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49028#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list