• I’m using relevanssi_content_to_index filter to add extra content from custom tables to a custom post type. However, there is no progress when reindexing.

    Looking at the browser console, there are multiple error messages like:

    “Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received”.

    Thank you in advance for your help!

    The page I need help with: [log in to see the link]

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

    (@msaari)

    Can you please show me the filter function you’re using? It sounds like the function might be broken.

    Thread Starter mrctulio

    (@mrctulio)

    Here it is:

    add_filter( 'relevanssi_content_to_index', 'zy_add_fields_from_custom_table', 10, 2 );
    function zy_add_fields_from_custom_table( $content, $post ) {
    
        if ( 'radio' == $post->post_type ) {
    
            /**
             * @param $content = conteúdo a ser indexado com os termos e palavras separados por um espa?o em branco
             */
    
            $id = $post->ID;
    
            global $wpdb;
    
            // zy_global
            $data = $wpdb->get_row( "SELECT * FROM zy_global WHERE id = {$id}" , ARRAY_A );
    
            $zid = $data['zid'];
            $estacao_id = $data['estacao_id'];
    
            if ( $data ) {
                $values = array_values($data);
                $content .= ' ' . implode(' ', $values);
            }
    
    
            /**
             * There are 3 other similar queries here in ...
             */
    
            // IES
            try {
    
                $data = $wpdb->get_row( "SELECT * FROM zy_cobertura_economia WHERE id_canal = {$estacao_id}", ARRAY_A );
                $zy_lista = json_decode($data['lista_ies'], true);
                foreach ($zy_lista as $item) {
                    $content .= ' ' . $item['sigla'] . " " . $item['nome'];
                }
    
            } catch (Exception $e) {
    
            }
    
        return $content;
    
        }
    
    }
    Plugin Author Mikko Saari

    (@msaari)

    The code has an error: move the return clause after the last brace so that the value is also returned for other post types than radio.

    Thread Starter mrctulio

    (@mrctulio)

    I’m sorry. I’ve made a mistake copying the code. Indeed, the return clause is placed after the brace, and this is the condition the errors ocurr.

    Please note that I’ve got a sucessfull indexing when I commented out the “IES” try-catch snippet (and also the other 3 try-catch queries). Even though this successful indexing was achieved by restarting (adding non indexed posts) after an initial halt.

    Plugin Author Mikko Saari

    (@msaari)

    Well, do you have something there that’s throwing exceptions? Might be worth looking into that. Why are you using try-catch there in the first place?

    Thread Starter mrctulio

    (@mrctulio)

    Just to make sure there is no errors.

    Plugin Author Mikko Saari

    (@msaari)

    There’s nothing obviously wrong in your code. It may be a performance issue – perhaps those database queries fail as many of them are done in quick succession? It’s hard to say. I would recommend adding some debugging code to the function to see what it does, how the database queries run and so on. Perhaps that will shed some light on this.

    The message channel error has nothing to do with this, though. That error might come from one of your Chrome extensions. Have you looked at the details of those errors to see where they’re coming from?

    Thread Starter mrctulio

    (@mrctulio)

    Nope. I’ll further debug. Thank you so much for support!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Error (message channel closed) using relevanssi_content_to_index to add content’ is closed to new replies.