0

I'm having an issue that my posts page displays "no posts found" while right above it, there is "All (1) | Published (1)" (it is a new installation). The post is also invisible on the live site, not only in the administration.

I guess it might have something to do with my database which is SQL Server using WP Db Abstraction. So I installed debug bar and found this query:

SELECT TOP 0 * FROM wp_posts WHERE 1=1 AND wp_posts.post_type LIKE 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status LIKE 'future' OR wp_posts.post_status LIKE 'draft' OR wp_posts.post_status LIKE 'pending' OR wp_posts.post_status LIKE 'private') ORDER BY wp_posts.post_date DESC

WP_Posts_List_Table->prepare_items, wp_edit_posts_query, wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, pdo_wpdb->query, pdo_wpdb->_post_query 

SELECT TOP 0 looks suspicious to me, what would you say? If that's indeed a bug, any suggestion on how to fix it?

3
  • 1
    This question is very narrow in scope and deals with a specific plugin and DB type not many WP users will have experience with. Considering you've already asked the same question on the WP.org support forums (the appropriate place for user support), I'm leaning towards closing this as "Too localized." But I'll listen to arguments to keep it open here. Also, please remember the plugin you're using has 0 "works" votes to 2 "broken" votes in the plugin repository ...
    – EAMann
    Feb 16, 2012 at 17:00
  • "select top 0" retrieves the column names. that might not be the problem.
    – rexposadas
    Feb 16, 2012 at 17:13
  • @rxn: If it's retriving columns, I would then expect another SELECTs from wp_posts, however, there are only those: SELECT post_status, COUNT( * ) AS num_posts FROM wp_posts... SELECT TOP 0 * FROM wp_posts WHERE 1=1 AND... SELECT COUNT(1) as Computed FROM wp_posts... None of them seems to be getting the posts. Feb 17, 2012 at 17:16

1 Answer 1

1

The problem is not with the "select top 0", but the way the query is changed behind the scenes. Even if you change it to "select * from...", it will break.

I managed to get this working by going to "wp-includes\query.php" file, and then removing the $limits variable from the query. This is not the best way to fix the problem, but will get the site working. It looks like the $limits is breaking the query, and the 'row offset' of SQL server is different to MySql. I don't know to much about how it all works, but I managed to get my installation working.

In the query.php file...

Find this line:

$this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";

change to:

$this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby";

This solution will only work while you still use the your current version of WP.

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.