├── README.md ├── composer.json ├── readme.txt └── relevanssi-acf-subfields.php /README.md: -------------------------------------------------------------------------------- 1 | # Relevanssi: add ACF subfields to index 2 | 3 | * Contributors: cftp 4 | * Requires at least: 3.6.1 5 | * Tested up to: 3.6.1 6 | * Stable tag: 0.2 7 | 8 | Finds subfields from ACF and feeds them to the Relevanssi indexer so they're findable in search. 9 | 10 | ## Description 11 | 12 | Finds subfields from ACF and feeds them to the Relevanssi indexer so they're findable in search. 13 | 14 | To have an ACF subfield, e.g. a Repeater, indexed, do this: 15 | 16 | 1. Go to the Relevanssi options 17 | 2. Scroll to "custom fields to index" 18 | 3. Add your fields in the format `[field_name]_%_[subfield_name]`, e.g. `sections_%_section_text` 19 | 4. Select "Build the Index", to recreate your Relevanssi index 20 | 21 | ## Changelog 22 | 23 | ### 0.2 24 | * BUGFIX: Fix typo in hook 25 | 26 | ### 0.1 27 | * First release 28 | 29 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "cftp/relevanssi-acf-subfields", 3 | "description": "Finds subfields from ACF and feeds them to the Relevanssi indexer so they're findable in search.", 4 | "homepage" : "https://github.com/cftp/relevanssi-acf-subfields/", 5 | "type" : "wordpress-plugin", 6 | "license" : "GPL-2.0+", 7 | "authors" : [ 8 | { 9 | "name" : "Code For The People Ltd", 10 | "homepage": "https://codeforthepeople.com/" 11 | } 12 | ], 13 | "require": { 14 | "composer/installers": "~1.0" 15 | } 16 | } -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Relevanssi: add ACF subfields to index === 2 | Contributors: cftp 3 | Requires at least: 3.6.1 4 | Tested up to: 3.6.1 5 | Stable tag: 0.2 6 | 7 | Finds subfields from ACF and feeds them to the Relevanssi indexer so they're findable in search. 8 | 9 | == Description == 10 | 11 | Finds subfields from ACF and feeds them to the Relevanssi indexer so they're findable in search. 12 | 13 | To have an ACF subfield, e.g. a Repeater, indexed, do this: 14 | 15 | 1. Go to the Relevanssi options 16 | 2. Scroll to "custom fields to index" 17 | 3. Add your fields in the format `[field_name]_%_[subfield_name]`, e.g. `sections_%_section_text` 18 | 4. Select "Build the Index", to recreate your Relevanssi index 19 | 20 | == Changelog == 21 | 22 | = 0.2 = 23 | * BUGFIX: Fix typo in hook 24 | 25 | = 0.1 = 26 | * First release 27 | -------------------------------------------------------------------------------- /relevanssi-acf-subfields.php: -------------------------------------------------------------------------------- 1 | version = 1; 87 | } 88 | 89 | // HOOKS 90 | // ===== 91 | 92 | /** 93 | * Hooks the WP filter relevanssi_content_to_index 94 | * 95 | * @filter relevanssi_content_to_index 96 | * 97 | * @param string $content Content to pass to Relevanssi 98 | * @param object $post A WP_Post object 99 | * @return string The content we're going to pass to Relevanssi 100 | * @author Simon Wheatley 101 | **/ 102 | public function filter_relevanssi_content_to_index( $content, WP_Post $post ) { 103 | // If we don't have ACF available, bail out 104 | if ( ! function_exists( 'the_repeater_field' ) ) 105 | return $content; 106 | 107 | $custom_fields = relevanssi_get_custom_fields(); 108 | foreach ( $custom_fields as $custom_field ) { 109 | if ( false === strpos( $custom_field, '%' ) ) 110 | continue; 111 | 112 | preg_match( '/([a-z0-9\_]+)_\%_([a-z0-9\_]+)/i', $custom_field, $matches ); 113 | $field_name = $matches[ 1 ]; 114 | $subfield_name = $matches[ 2 ]; 115 | $num_fields = get_post_meta( $post->ID, $field_name, true ); 116 | for ( $i = 0; $i < $num_fields; $i++ ) { 117 | $raw = get_post_meta( $post->ID, "{$field_name}_{$i}_{$subfield_name}", true ); 118 | // Copied and pasted from Relevanssi 119 | remove_shortcode('noindex'); 120 | add_shortcode('noindex', 'relevanssi_noindex_shortcode_indexing'); 121 | $disable_shortcodes = get_option('relevanssi_disable_shortcodes'); 122 | $shortcodes = explode(',', $disable_shortcodes); 123 | foreach ($shortcodes as $shortcode) { 124 | remove_shortcode(trim($shortcode)); 125 | } 126 | remove_shortcode('contact-form'); // Jetpack Contact Form causes an error message 127 | remove_shortcode('starrater'); // GD Star Rating rater shortcode causes problems 128 | $value = do_shortcode( $raw ) . PHP_EOL; 129 | $content .= $value; 130 | } 131 | } 132 | return $content; 133 | } 134 | 135 | } 136 | 137 | 138 | // Initiate the singleton 139 | Relevanssi_ACF_Subfields::init(); 140 | 141 | --------------------------------------------------------------------------------