• Resolved Rohjay

    (@redearryan)


    Hey guys,

    I’m getting a fatal error on searches that include indexed posts that have since been deleted.

    The error is as follows:

    PHP Fatal error: Uncaught TypeError: Cannot access offset of type WP_Error in isset or empty in /var/www/html/wp-content/plugins/relevanssi-premium/lib/compatibility/wp-members.php:35
    Stack trace:
        #0 /var/www/html/wp-includes/class-wp-hook.php(324): relevanssi_wpmembers_compatibility()
        #1 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_filters()
        #2 /var/www/html/wp-content/plugins/relevanssi-premium/premium/search-multi.php(193): apply_filters()
        #3 /var/www/html/wp-content/plugins/relevanssi-premium/lib/search.php(595): relevanssi_search_multi()
        #4 /var/www/html/wp-content/plugins/relevanssi-premium/lib/search.php(88): relevanssi_do_query()
        #5 /var/www/html/wp-includes/class-wp-hook.php(324): relevanssi_query()
        #6 /var/www/html/wp-includes/plugin.php(256): WP_Hook->apply_filters()
        #7 /var/www/html/wp-includes/class-wp-query.php(3146): apply_filters_ref_array()
        #8 /var/www/html/wp-includes/class-wp-query.php(3824): WP_Query->get_posts()
        #9 /var/...', referer: https://example.com/?s=test

    Code responsible relevanssi-premium/lib/compatibility/wp-members.php :

    // function relevanssi_wpmembers_compatibility...
        $post_meta = get_post_meta($post_id, '_wpmem_block', true);
        // The next line fatals (line 35)
        $post_type = isset($wpmem->block[relevanssi_get_post_type($post_id)])
            ? $wpmem->block[relevanssi_get_post_type($post_id)]
            : 0;
    
        if ('1' === $post_meta) {
            $post_ok = false;
        } elseif ('1' === $post_type && '0' !== $post_meta) {
            $post_ok = false;
        }

    As you might imagine, if the post doesn’t exist anymore (but is still referenced in the index), the line $post_type = isset($wpmem->block... is a little brittle.

    One fix is to run a complete re-indexing, but I think the more permanent solution would be to resolve the code shortcoming here.

    Thank you very much for an awesome plugin!

    Cheers,
    Ryan “Rohjay” Oeltjenbruns

    • This topic was modified 5 months, 4 weeks ago by Rohjay.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Relevanssi should deindex deleted posts. Relevanssi uses the delete_post action to notice when a post is deleted. How do you delete posts so that delete_post doesn’t trigger? That’s the root problem.

    Thread Starter Rohjay

    (@redearryan)

    Hey Mikko,

    You’re not wrong, sir! That is an issue when things get deleted in non-standard ways. In the realm of WordPress though… not an impossible scenario. To be honest, I don’t know how it’s happening on my client’s site – or what took place to get to this state.

    I figured you’d want to know about this corner case – I can continue to hack around it to prevent fatals in the event this happens again =]

    Cheers,
    Ryan

    Plugin Author Mikko Saari

    (@msaari)

    I think I’ll have to let this be. This is a very rare case: Relevanssi has ignored this possibility for 15 years now, and this is the first time this scenario comes up. I think there may have been a couple of other cases where ghost posts remain in the index and cause smaller trouble.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.