• We have created custom Gutenberg-Blocks with ACF-Text-Content, which are used within posts.

    When we add these blocks to posts, the content is visible for Relevanssi, and
    can be searched. The right content will also show up in the relevanssi debug pane.

    But as soon as I recreate the index manually, the debugging pane shows completely other content then within the post.

    What can be the cause for this behavior?

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

    (@msaari)

    Is it possible that in the general indexing context the custom block gets confused somehow? Does the block use the global $post or any post loops?

    Thread Starter Alex R.

    (@dreamfish)

    Hi @msaari, we are using the block in a custom post type single-page template, which
    uses get_template_part in a standard wordpress loop.

    get_header();
    
    while ( have_posts() ) :
    	the_post();
    	get_template_part( 'template-parts/content/content', 'wiki' );
    endwhile; // End of the loop.
    
    get_footer();
    Plugin Author Mikko Saari

    (@msaari)

    The template isn’t related; Relevanssi never sees that. Relevanssi just sees the post content as it is in the database, and renders the blocks in the post content.

    Does the block code load any posts or touch the global query or post variables?

    svebal

    (@svebal)

    No, it’s only

    $wiki_text = get_field( 'wiki_text' );
    
    echo $wiki_text

    with some HTML around.

    The ACF field is declared in this way in the ACF local JSON

    {
    "key": "field_61689599ccef2",
    "label": "Text",
    "name": "wiki_text",
    "type": "wysiwyg",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
       "width": "",
       "class": "",
       "id": ""
    },
    "default_value": "",
    "tabs": "all",
    "toolbar": "basic",
    "media_upload": 0,
    "delay": 0
    }

    Nothing special, it’s a block with a WYSIWYG editor, wich can dropped into the editor area in the backend. Ofcourse there are other blocks like Gutenberg “wp:columns”, a headline or list with static links in the post content.

    • This reply was modified 3 years ago by svebal.
    Plugin Author Mikko Saari

    (@msaari)

    I agree – there’s nothing special there. So, what exactly happens when things go wrong? Where is the wrong content coming and is any correct content left? This sounds like solving the mystery requires some closer debugging in the indexing process to see where it goes wrong.

    Thread Starter Alex R.

    (@dreamfish)

    I can reproduce the problem when I do the following:

    Adding “Word1” into the block, and “Word2” as normal WordPress Paragraph-Block onto the post.

    When searching, Relevanssi will find both “Word1” and “Word2”.

    Now I reindex all pages in Relevanssi Search Options.

    When searching now, Relevanssi will NOT find “Word1”, but still “Word2”.

    Saving afterwards the Custom Post Type post again, Relevanssi will find again “Word1” and “Word2”.

    Plugin Author Mikko Saari

    (@msaari)

    Ok, that makes sense: when you save the post and the context is that all content is registered, but when the bulk indexer runs, context is somehow different, the block isn’t rendered correctly.

    I’d check this: $wiki_text = get_field( 'wiki_text' ); When you don’t specify the post ID for get_field(), it assumes the current post, and perhaps that’s just not working correctly when the Relevanssi bulk indexer runs. I’m not sure how get_field() works exactly, but Relevanssi does set the global $post, so this should work:

    global $post;
    $wiki_text = get_field( 'wiki_text', $post->ID );
    Thread Starter Alex R.

    (@dreamfish)

    Hi,

    when using global $post as you mentioned, and add the ID to the ACF-Field,
    the content stays empty.

    When dumping $post on the post-template, we can see the entire content, including
    the specific block.

    Thread Starter Alex R.

    (@dreamfish)

    This is what we tested:

    global $post;
    $wiki_headline = get_field( 'wiki_headline', $post->ID );
    $wiki_text = get_field( 'wiki_text', $post->ID );
    ?>
    
    <section class="wiki-single content-row">
    	<div class="content-row-inner">
    
    		<div class="wiki-single-box">
    			<div class="wiki-single-text" ><?php echo $wiki_text ?></div>
    		</div>
    		
    	</div>
    </section>
    
    <?php
    Plugin Author Mikko Saari

    (@msaari)

    If you do error logging, what does the $post contain when Relevanssi indexes everything?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Problem with Index and ACF Gutenberg-Blocks’ is closed to new replies.