Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pm_replace_custom_field_tags($default_uri, $native_slug, $element, $slug, $native_uri) {
- // 1. Insert %new_dynamic_tag% in permastructure settings (Tools -> Permalink Manager -> Permsatructures)
- $tag = '%new_dynamic_tag%';
- // 2A. Check if value set with ACF plugin can be parsed
- if(function_exists('get_field')) {
- $acf_element_id = (!empty($element->ID)) ? $element->ID : "{$element->taxonomy}_{$element->term_id}";
- $field_object = get_field_object($custom_field, $acf_element_id);
- // Extra function to format and get the value (use $custom_field_value variable)
- // ...
- // ...
- // $custom_field_value = ...;
- }
- // 2B. Use native functions to get custom field value (if it cannot be parsed from ACF)
- if(empty($custom_field_value)) {
- if(!empty($element->ID)) {
- $custom_field_value = get_post_meta($element->ID, $custom_field, true);
- } else if(!empty($element->term_id)) {
- $custom_field_value = get_term_meta($element->term_id, $custom_field, true);
- } else {
- $custom_field_value = "";
- }
- }
- // Make sure that custom field is a string and replace %new_dynamic_tag% with custom field value (if it is set)
- if(!empty($custom_field_value) && is_string($custom_field_value)) {
- $default_uri = str_replace(tag, Permalink_Manager_Helper_Functions::sanitize_title($custom_field_value), $default_uri);
- }
- return $default_uri;
- }
- add_filter( 'permalink_manager_filter_default_post_uri', 'pm_replace_custom_field_tags', 9, 5 );
- add_filter( 'permalink_manager_filter_default_term_uri', 'pm_replace_custom_field_tags', 9, 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement