0

given this code:

    $args = array(
        'post_type' => 'post',
        'post_status' => 'publish',
        'cat' => $cat,
        'orderby' => 'date',
        'order' => 'DESC',
        'publish_from' => 1,
        'publish_to' => 1,
        's' => $s,
        'tag' => $tag,
        'paged' => (int)$next,
        'posts_per_page' => (int)$ppp
    );
    $query = new WP_Query($args);
    echo $query->request.'!<br>';
    $query = $query->get_posts();
    echo sizeof($query);die;

it echoes the following SQL:

SELECT SQL_CALC_FOUND_ROWS wp_16_posts.* FROM wp_16_posts WHERE 1=1 AND (wp_16_posts.publish_to IS NULL OR wp_16_posts.publish_to > now()) AND (wp_16_posts.publish_from IS NULL OR wp_16_posts.publish_from < now()) AND (((wp_16_posts.post_title LIKE '{77b35c99deebcd176e45c5740dc2f5707adf3f48c63f743d524469d6161873c4}rosszkor233{77b35c99deebcd176e45c5740dc2f5707adf3f48c63f743d524469d6161873c4}') OR (wp_16_posts.post_excerpt LIKE '{77b35c99deebcd176e45c5740dc2f5707adf3f48c63f743d524469d6161873c4}rosszkor233{77b35c99deebcd176e45c5740dc2f5707adf3f48c63f743d524469d6161873c4}') OR (wp_16_posts.post_content LIKE '{77b35c99deebcd176e45c5740dc2f5707adf3f48c63f743d524469d6161873c4}rosszkor233{77b35c99deebcd176e45c5740dc2f5707adf3f48c63f743d524469d6161873c4}'))) AND wp_16_posts.post_type = 'post' AND ((wp_16_posts.post_status = 'publish')) ORDER BY wp_16_posts.post_date DESC LIMIT 0, 8

running this in an SQL browser, it returns nothing. But above I echo the length of the result - its 8! So WP_Query cant run that SQL what I see... what can be wrong? Its the newest WordPress

1

$wp_query->result is not the final stage of the query. It needs to be passed through $wpdb to be properly executed.

The main issue is the fact that the LIKE wildcards % have not been unescaped. If you replace the {77b35c9 etc.} sets of characters, including the brackets, with % you should get pretty much the final query:

SELECT SQL_CALC_FOUND_ROWS wp_16_posts.* FROM wp_16_posts WHERE 1=1 AND (wp_16_posts.publish_to IS NULL OR wp_16_posts.publish_to > now()) AND (wp_16_posts.publish_from IS NULL OR wp_16_posts.publish_from < now()) AND (((wp_16_posts.post_title LIKE '%rosszkor233%') OR (wp_16_posts.post_excerpt LIKE '%rosszkor233%') OR (wp_16_posts.post_content LIKE '%rosszkor233%'))) AND wp_16_posts.post_type = 'post' AND ((wp_16_posts.post_status = 'publish')) ORDER BY wp_16_posts.post_date DESC LIMIT 0, 8
  • thats right, but it still returns nothing in SQL browser... – user170270 Jun 19 at 10:04
  • Then you probably don't have results. Is there a reason that you expect results? Presumably you're not getting results, or you wouldn't be checking the SQL. – Jacob Peattie Jun 19 at 10:14
  • of course, the "rosszkor233" is a madeup word, doesnt exists. But the question is, why there are result hits in ->get_posts() ... – user170270 Jun 19 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.