Astra_Target_Rules_Fields::get_location_by_key( string $key )
Get location label by key.
Description
Parameters
- $key
-
(string) (Required) Location option key.
Return
(string)
Source
File: classes/modules/target-rule/class-astra-target-rules-fields.php
public static function get_location_by_key( $key ) { if ( ! isset( self::$location_selection ) || empty( self::$location_selection ) ) { self::$location_selection = self::get_location_selections(); } $location_selection = self::$location_selection; foreach ( $location_selection as $location_grp ) { if ( isset( $location_grp['value'][ $key ] ) ) { return $location_grp['value'][ $key ]; } } if ( strpos( $key, 'post-' ) !== false ) { $post_id = (int) str_replace( 'post-', '', $key ); return get_the_title( $post_id ); } // taxonomy options. if ( strpos( $key, 'tax-' ) !== false ) { $tax_id = (int) str_replace( 'tax-', '', $key ); $term = get_term( $tax_id ); if ( ! is_wp_error( $term ) ) { $term_taxonomy = ucfirst( str_replace( '_', ' ', $term->taxonomy ) ); return $term->name . ' - ' . $term_taxonomy; } else { return ''; } } return $key; }
Expand full source code Collapse full source code View on Trac