In lib/search.php, find this:
$q = "SELECT post.ID
FROM $wpdb->posts post
LEFT JOIN $wpdb->posts parent ON (post.post_parent=parent.ID)
WHERE
(((parent.ID is null OR parent.ID=post.ID) AND (post.post_status IN ($valid_status)))
OR
(post.post_status='inherit'
AND(
(parent.ID is not null AND (parent.post_status IN ($valid_status)))
OR (post.post_parent=0)
)
))
$restriction";
If you add
var_dump($q); exit();
after that and then build the index, you should see the MySQL query echoed out. What does it say? If you change the SELECT post.ID
to SELECT post.ID, post.post_type
and run the query on the MySQL server, do you get the correct post types or not?
Thanks for the response!
I think you meant lib/indexing.php, not search.php. Anyway, here’s what var_dump($q) got me on one of the sites:
SELECT post.ID FROM wp_posts post LEFT JOIN wp_posts parent ON (post.post_parent=parent.ID) WHERE (((parent.ID is null OR parent.ID=post.ID) AND (post.post_status IN ('publish','draft','private','pending','future'))) OR (post.post_status='inherit' AND( (parent.ID is not null AND (parent.post_status IN ('publish','draft','private','pending','future'))) OR (post.post_parent=0) ) )) AND post.post_type IN ('post', 'page', 'CUSTOM1', 'CUSTOM2')
CUSTOM2 is the post type that is missing from the index.
However, when I changed that to “SELECT post.post_type” and run the query, it returns a handful of rows of each post type except CUSTOM2.
I’ll evaluate that query now to see what about it is making it exclude CUSTOM2. Thanks!
Yes, sorry, of course I meant lib/indexing.php.
You’re not running the latest version. The current MySQL query is:
SELECT post.ID FROM wp_posts post LEFT JOIN wp_posts parent ON (post.post_parent=parent.ID) WHERE (post.post_status IN ('publish','draft','private','pending','future') OR (post.post_status='inherit' AND ( (parent.ID is not null AND (parent.post_status IN ('publish','draft','private','pending','future'))) OR (post.post_parent=0)
) )) AND post.post_type IN ('post', 'page', 'CUSTOM1', 'CUSTOM2')
Hopefully I got the right number of parentheses in there. You can try if that’s any better.
That query works.
I have 3.3.2 installed, which is the latest version available on WordPress.org.
Ok, great. You’re right – that code is from 3.3.3, not 3.3.2. Good to hear it works. I’ll probably release 3.3.3 tomorrow, if not today.
Thanks, I’ll keep an eye out for it. Thanks for the help and great plugin!
For anyone in need of a temp patch until 3.3.3 is out, I was able to get things working by replacing lines 58-70 of lib/indexing.php with:
$q = "SELECT post.ID
FROM $wpdb->posts post
LEFT JOIN $wpdb->posts parent ON (post.post_parent=parent.ID)
WHERE
(((post.post_status IN ($valid_status)))
OR
(post.post_status='inherit'
AND(
(parent.ID is not null AND (parent.post_status IN ($valid_status)))
OR (post.post_parent=0)
)
))
$restriction";