Under the SSO > Advanced > Custom Meta tab, you can specify custom field names (aka post/user/term meta) that WPSSO Core will use to retrieve values for some custom options in the Social and Search Optimization metabox. If those values are term names instead of post meta, you can use the WordPress ‘get_post_metadata’ filter to provide those names to WPSSO Core as post meta.
As an example, we can enter “_productbrand” for the Product Brand Custom Field value, and use the following filter to provide term names for that custom field (aka post meta).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
add_filter( 'get_post_metadata', 'get_taxonomy_product_brands', 10, 4 ); function get_taxonomy_product_brands( $ret, $post_id, $meta_key, $single ) { if ( $meta_key === '_productbrand' ) { // the custom field value $ret = $single ? null : array(); // new array if $single is false foreach ( wp_get_post_terms( $post_id, 'pwb-brand' ) as $term ) { if ( ! empty( $term->name ) { // just in case if ( $single ) { return $term->name; // stop here } else { $ret[] = $term->name; } } } $ret = empty( $ret ) ? null : $ret; // return null if no terms } return $ret; } |