plugin development – wpdb->prepare creates random string for % character

Question

I have a query like this,

    $query = "... user LIKE '%-guest-%' ...";

I’m using WordPress 6.1.1 and non of the those ( How do you properly prepare a %LIKE% SQL statement? ) and those (prepare() not working) solutions worked for me. WordPress created long random string instead of % character on all queries I tried. I also tried deactivating all plugins and loading a default theme, but I got the same results.

When I did

    echo $wpdb->prepare(" LIKE '%%-guest-%%'" );
    echo $wpdb->prepare(" LIKE '%-guest-%'" );
    echo $wpdb->prepare("%s", "%-guest-%" );
    echo $wpdb->prepare("%%%s", "-guest-%" );
    echo $wpdb->prepare("%%%s%%", "-guest-" );
    echo $wpdb->prepare("'%%%s%%'", "-guest-" );
    echo $wpdb->prepare("%s", "%%-guest-%%" );

I got those outputs in order. String is randomly generated on every page refresh.

LIKE '{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}-guest-{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}'

LIKE '{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}-guest-{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}'

    '{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}-guest-{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}'

 {abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}-guest-{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263} 

{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}-guest-{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}

'{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}-guest-{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}'

{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}-guest-{abaadfbc0a08cdc488b3b5787097ca4c33fd03adf665dfe397675231bcd7d263}

0
doraemon 1 year 2023-03-01T12:49:27-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse