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

    (@msaari)

    If I understand this right, you’ve probably set Relevanssi to index the post type that has the individual blocks. Relevanssi should probably just index post and page. If you can show me a screenshot of your Relevanssi indexing settings page, that would help.

    Thread Starter niekmagelaan

    (@niekmagelaan)

    Hi Mikko,

    The settings are indeed set to index the custom post type ‘block’. These blocks are used to lay-out and fill the pages with content. This content needs to be available in the search results, hence the custom post type is indexed.

    I would like to be able to redirect to the page where these ‘blocks’ are used not the block itself, since they are never a page on their own, but always part of a page. (a certain block is always a child of a page and a page can have multiple blocks but only belong to 1 page)

    I hope I made things clear.

    Thanks in advance!

    Plugin Author Mikko Saari

    (@msaari)

    This is not the correct approach. Relevanssi should be set to index the pages, and as part of the pages index the blocks that appear on the pages. Indexing the block post type directly will not work, because Relevanssi can’t know where those blocks appear.

    How do those blocks work? How are they connected on the pages? If Relevanssi isn’t able to automatically index the block content for the pages, the correct solution is to add a relevanssi_content_to_index filter function that reads in the block content for the posts and adds it in the post content so that Relevanssi can index it as part of the post.

    Thread Starter niekmagelaan

    (@niekmagelaan)

    Thanks for the quick response. The pages are already set to be indexed, but the content from the custom fields doesn’t seem to be indexed with it.

    I did say earlier that ‘block’ is a custom post type but that’s not true. each ‘block’ is a repeatable field group (made with Toolset Types).

    like this: https://pedeobe.webhosting.be/wp-content/uploads/2020/03/Schermafbeelding-2020-03-26-om-08.58.55.png

    EDIT: I followed this guide: https://toolset.com/documentation/user-guides/views/searching-texts-custom-fields-views-relevanssi/

    • This reply was modified 4 years, 8 months ago by niekmagelaan.
    Plugin Author Mikko Saari

    (@msaari)

    If the content is stored in custom fields, then the question is –?where are those custom fields stored? If the custom fields are related to the main page, then setting Relevanssi to index custom fields should work fine.

    However, if the custom fields are stored in the block type posts, then Relevanssi won’t see them when it’s indexing the main page. In that case you’d need a relevanssi_content_to_index filter function that will read the custom field content from the block posts connected to the main page.

    How does the page look like in the wp_posts database table? Are the blocks added as shortcodes or with some other method? Toolset support may also be able to help you with this.

    Thread Starter niekmagelaan

    (@niekmagelaan)

    Each ‘block’ is a post in the wp_posts table with the ‘post_parent’ column connecting it to a page. Each ‘block’ is just a repeatable field group made with Toolset, which is visible depending on the template used.

    I do a query in the template to get all ‘block’ repeatable fields belonging to that page and display them that way.

    Plugin Author Mikko Saari

    (@msaari)

    Ok, the same query could probably be used for indexing the block content for the main post (but not if it’s a post loop that changes the global $post object, that’s poison for Relevanssi).

    add_filter( 'relevanssi_content_to_index', 'rlv_add_block_content', 10, 2 );
    function rlv_add_block_content( $content, $post ) {
        // Fetch block content for the post in $post here
        $content .= ' ' . $block_content;
        return $content;
    }
    Thread Starter niekmagelaan

    (@niekmagelaan)

    Thank you very much for the proposed solution. I’ll try this out and get back to you with the results.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Link to page where custom field is shown’ is closed to new replies.