Where are you pasting your code above? What file or perhaps a custom plugin?
Not seeing anything wrong with it as is, but I am kind of wondering if it’s being run after the filter has run, or if not in the right conditions somehow.
Thread Starter
sebgc
(@sebgc)
Thanks for the assist. The code is pasted into my theme’s functions.php
Thread Starter
sebgc
(@sebgc)
Any suggestions for the fix?
Thread Starter
sebgc
(@sebgc)
There must have been an issue with my variable names – I have since corrected the implemented code and it works as expected, for example:
/* Algolia customisations */
add_filter( 'algolia_post_shared_attributes', 'complyadvantage_post_attributes', 10, 2 );
add_filter( 'algolia_searchable_post_shared_attributes', 'complyadvantage_post_attributes', 10, 2 );
/**
* @param array $shared_attributes
* @param WP_Post $post
*
* @return array
*/
function complyadvantage_post_attributes( array $shared_attributes, WP_Post $post ) {
if ( 'resource' !== $post->post_type ) {
// We only want to add an attribute for the 'resource' post type.
// Here the post isn't a 'resource', so we return the attributes unaltered.
return $shared_attributes;
}
$shared_attributes['call_to_action_url'] = get_post_meta( $post->ID, 'wpcf-call-to-action-url', true );
// Always return the value we are filtering.
return $shared_attributes;
}