algolia / algoliasearch-wordpress

❌🗑🙅‍♂️ Algolia Search plugin for WordPress is no longer supported. Please use our API client guide instead
https://www.algolia.com/doc/integration/wordpress/getting-started/quick-start/
GNU General Public License v2.0
359 stars 114 forks source link

Unable to index custom Toolset attributes to Algolia Database #787

Open WinstonGFX opened 6 years ago

WinstonGFX commented 6 years ago

What did you expect to happen?

I've created a custom taxonomy with Toolset called an Employee. For all employees, I've got custom fields of information that get populated with a form. I'm trying to sync these custom fields to my Algolia database my added code to functions.php like shown in the ACF example: https://community.algolia.com/wordpress/advanced-custom-fields.html

What happened instead?

Custom fields are not available through the Algolia dashboard and cannot be called to the site with Instant Search.

How can we reproduce this behavior?

add_action( 'wp_enqueue_scripts', 'oceanwp_child_enqueue_parent_style' );

/**
 * @param array   $attributes
 * @param WP_Post $post
 *
 * @return array
 */

function my_employee_attributes( array $attributes, WP_Post $post ) {

    if ( 'employees' !== $post->post_type ) {
        return $attributes;
    }

    $attributes['first_name'] = get_post_meta( $post->ID, 'first_name', true );
    $attributes['last_name'] = get_post_meta( $post->ID, 'last_name', true );
    $attributes['profile'] = get_post_meta( $post->ID, 'profile_photo', true );
    $attributes['nicknames'] = get_post_meta( $post->ID, 'wpcf-nicknames', false );
    $attributes['office'] = get_post_meta( $post->ID, 'wpcf-office', true );
    $attributes['department'] = get_post_meta( $post->ID, 'wpcf-department', true );
    $attributes['position'] = get_post_meta( $post->ID, 'wpcf-position', true );
    $attributes['email'] = get_post_meta( $post->ID, 'wpcf-email', true );
    $attributes['cell'] = get_post_meta( $post->ID, 'wpcf-cell', true );
    $attributes['start_date'] = get_post_meta( $post->ID, 'wpcf-start_date', true );
    $attributes['quote'] = get_post_meta( $post->ID, 'wpcf-quote', true );
    $attributes['why_love_design'] = get_post_meta( $post->ID, 'wpcf-why_love_design', false );
    $attributes['portfolio'] = get_post_meta( $post->ID, 'wpcf-portfolio', true );
    $attributes['birthday'] = get_post_meta( $post->ID, 'wpcf-birthday', true );
    $attributes['instagram'] = get_post_meta( $post->ID, 'wpcf-instagram', true );
    $attributes['type_of_clients'] = get_post_meta( $post->ID, 'wpcf-type_of_clients', false );
    $attributes['project_experience'] = get_post_meta( $post->ID, 'wpcf-project_experience', false );
    $attributes['regional_knowledge'] = get_post_meta( $post->ID, 'wpcf-regional_knowledge', false );
    $attributes['skills'] = get_post_meta( $post->ID, 'wpcf-skills', false );
    $attributes['td_stuff'] = get_post_meta( $post->ID, 'wpcf-td_stuff', false );
    $attributes['special_interests'] = get_post_meta( $post->ID, 'wpcf-special_interests', false );
    $attributes['languages'] = get_post_meta( $post->ID, 'wpcf-languages', false );
    $attributes['favorites'] = get_post_meta( $post->ID, 'wpcf-favorites', false );

    // Always return the value we are filtering.
    return $attributes;
}

add_filter( 'algolia_searchable_post_shared_attributes', 'my_employee_attributes', 10, 2 );
add_filter( 'algolia_post_shared_attributes', 'my_employee_attributes', 10, 2 );

Can you provide a link to a page which shows this issue? Password protected page, so no unfortunately.

Technical info

WinstonGFX commented 6 years ago

Any ideas on this?

WinstonGFX commented 6 years ago

Still need assistance with this – any ideas?

WinstonGFX commented 5 years ago

@rayrutjes Still in need of assistance with this. I can't get my custom fields to push to my Algolia index.