Title: Adding more fields to doc1 variable
Last modified: August 22, 2016

---

# Adding more fields to doc1 variable

 *  Resolved [Pilsgaard](https://wordpress.org/support/users/pilsgaard/)
 * (@pilsgaard)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/)
 * Hi. Thank you for a really impressive plugin!
 * I would like to add more fields to the $doc1 varialbe in the create_solr_document_from_post_or_attachment
   function.
 * If you add a filter before you return it, i could read the $doc1->id and add 
   or replace the other fields in the object.
 * E.g i want to add the image path to one of our image sizes and the rating saved
   in the post_meta, so i can use them on my search result page, without using the
   database.
 * Kindly regards,
    Casper Pilsgaard
 * [https://wordpress.org/plugins/wpsolr-search-engine/](https://wordpress.org/plugins/wpsolr-search-engine/)

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

 *  Thread Starter [Pilsgaard](https://wordpress.org/support/users/pilsgaard/)
 * (@pilsgaard)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/#post-5908341)
 * Just tried to add this line in class-wp-solr.php:917 just before the return $
   doc1;
 * $doc1 = apply_filters( ‘wp_solr_plugin_filter_doc1’, $doc1, $updateQuery, $opt,
   $post, $attachment_body );
 * And this function in my theme functions.php
    function sv_wp_solr_plugin_filter_doc1(
   $doc1, $updateQuery, $opt, $post, $attachment_body ) {
 *  $doc1->testing = “MyTest”;
 *  return $doc1;
    } add_filter(‘wp_solr_plugin_filter_doc1’, ‘sv_wp_solr_plugin_filter_doc1’,
   10, 5 );
 * And its working (have to add testing to the solr schema offcource).
    I dont know
   what all the variables to the create_solr_document_from_post_or_attachment function
   is doing, so i just added all of them if i need them.
 * Hope you can add something like this to the plugin. : -)
 * Regards,
    Casper
 *  Plugin Author [WPSOLR](https://wordpress.org/support/users/wpsolr/)
 * (@wpsolr)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/#post-5908342)
 * Thanks.
 * That’s a good idea indeed.
 * But the data you intend to add to the index must be part of the current schema,
   or I must extend the current schema. Else you’ll be stuck for ever to merge your
   schema and WPSOLR schema.
 * For instance, if your data is a custom field, it is already indexed and can be
   displayed as a facet.
 *  Thread Starter [Pilsgaard](https://wordpress.org/support/users/pilsgaard/)
 * (@pilsgaard)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/#post-5908394)
 * If someone is extending the plugin via filters, they probably got access to the
   schema and knows what they are doing. I think the custom posts and facets you
   already made in the plugin are awesome. This is only for really specific use.
 * I installed a fresh install of solr5 and they got a managed schema, so solr just
   adds the new field based on the datatype when i add more to $doc1.
 * e.g the $doc1->testing showed up automatically without a schema change, when 
   i runned the code above.
 * You could make a solr5 version of the plugin, where people dont need to make 
   any schema changes.
 * Regards,
    Casper
 *  Plugin Author [WPSOLR](https://wordpress.org/support/users/wpsolr/)
 * (@wpsolr)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/#post-5908398)
 * I agree.
 * If one is aware of the consequences, a filter is great indeed.
 * Do you have an urgent need for WPSOLR’s filter ? I’d rather package it with the
   next release.
 *  Thread Starter [Pilsgaard](https://wordpress.org/support/users/pilsgaard/)
 * (@pilsgaard)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/#post-5908470)
 * Im going to production this week, but i just use my own line. Can i subscribe
   to get a mail when there is a new release?
 * Or you can write in this thread, if you would like me to test the filters.
 * Thanks for the quick answers!
 * Regards,
    Casper
 *  Plugin Author [WPSOLR](https://wordpress.org/support/users/wpsolr/)
 * (@wpsolr)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/#post-5908598)
 * I’ll get you updated indeed.

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

The topic ‘Adding more fields to doc1 variable’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wpsolr-search-engine_b2dbdc.svg)
 * [WPSOLR - Elasticsearch and Solr search](https://wordpress.org/plugins/wpsolr-search-engine/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpsolr-search-engine/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpsolr-search-engine/)
 * [Active Topics](https://wordpress.org/support/plugin/wpsolr-search-engine/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpsolr-search-engine/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpsolr-search-engine/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [WPSOLR](https://wordpress.org/support/users/wpsolr/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/adding-more-fields-to-doc1-variable/#post-5908598)
 * Status: resolved