Support » Plugin: Relevanssi - A Better Search » Custom Post Type excluded from index since 3.3.2

  • Resolved ChrisLowrance

    (@chrislowrance)


    Since after adding the 3.3.2 update on two sites and reindexing, each site stopped indexing one of their custom post types. They were indexed fine before, and are set to be public and searchable. The odd thing is they each index other custom post types fine, and I can’t tell what the single types each site is now failing to index have in common.

    Any idea what might cause this?

    https://wordpress.org/plugins/relevanssi/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mikko Saari

    (@msaari)

    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?

    Thread Starter ChrisLowrance

    (@chrislowrance)

    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!

    Plugin Author Mikko Saari

    (@msaari)

    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.

    Thread Starter ChrisLowrance

    (@chrislowrance)

    That query works.

    I have 3.3.2 installed, which is the latest version available on WordPress.org.

    Plugin Author Mikko Saari

    (@msaari)

    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.

    Thread Starter ChrisLowrance

    (@chrislowrance)

    Thanks, I’ll keep an eye out for it. Thanks for the help and great plugin!

    Thread Starter ChrisLowrance

    (@chrislowrance)

    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";
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Post Type excluded from index since 3.3.2’ is closed to new replies.