Title: Using custom posts as building blocks
Last modified: November 21, 2018

---

# Using custom posts as building blocks

 *  [eric3d](https://wordpress.org/support/users/eric3d/)
 * (@eric3d)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/using-custom-posts-as-building-blocks/)
 * I am using custom posts as blocks on a page. None of those custom posts are accessed
   directly, but their content is included in another page.
 * Is Relevanssi able to search the content of those custom posts and link the results
   to the public page where the block appears?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/using-custom-posts-as-building-blocks/#post-10905465)
 * Yes, but it may need some help from you. You need to add some code that will 
   tell Relevanssi that posts A, B, and C are related to the page X and their contents
   should be indexed with the page X.
 * How that exactly happens depends on how you’re connecting the posts to the pages,
   but for example you can use the `relevanssi_content_to_index` filter hook to 
   add extra content to pages before they are indexed. Let’s assume you have the
   custom post IDs in a custom field `block_id`:
 *     ```
       add_filter( 'relevanssi_content_to_index', 'rlv_custom_blocks', 10, 2 );
       function rlv_custom_blocks( $content, $post ) {
           $custom_fields = get_post_meta( $post->ID, 'block_id' );
           foreach ( $custom_fields as $field ) {
               $custom_post = get_post( $field );
               $content .= $custom_post->post_content;
           }
           return $content;
       }
       ```
   
 * If you want to have the search excerpts use the same post content as building
   material, you can also apply the same function when doing excerpts:
 * `add_filter( 'relevanssi_pre_excerpt_content', 'rlv_custom_blocks', 10, 2 );`
 * Since the parameters are the same, you can just use the same function both for
   indexing and excerpts.
 *  Thread Starter [eric3d](https://wordpress.org/support/users/eric3d/)
 * (@eric3d)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/using-custom-posts-as-building-blocks/#post-10907370)
 * Thanks for the quick response. I’ll run some tests.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using custom posts as building blocks’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=3529670)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [eric3d](https://wordpress.org/support/users/eric3d/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/using-custom-posts-as-building-blocks/#post-10907370)
 * Status: not resolved