Skip to content

Instantly share code, notes, and snippets.

@maciejbis
Last active February 20, 2025 11:49
Show Gist options
  • Save maciejbis/e9ee4078de958ab03dbacf0b0fccd7f6 to your computer and use it in GitHub Desktop.
Save maciejbis/e9ee4078de958ab03dbacf0b0fccd7f6 to your computer and use it in GitHub Desktop.
Support Voxel custom fields in Permastructure formats
<?php
/**
* Support Voxel custom fields in Permastructure formats
*/
function pm_new_permastructure_tag( $custom_field_value, $custom_field, $element ) {
if ( empty( $custom_field_value ) && class_exists( '\Voxel\Post' ) && method_exists( '\Voxel\Post', 'get' ) && ! empty( $element->post_type ) ) {
$voxel_post = \Voxel\Post::get( $element );
if ( method_exists( $voxel_post, 'get_field' ) ) {
$field = $voxel_post->get_field( $custom_field );
if ( ! empty( $field ) && method_exists( $field, 'get_value_from_post' ) ) {
$rel_posts = $field->get_value_from_post();
if ( ( is_array( $rel_posts ) ) ) {
if ( ! empty( $rel_posts[0] ) && is_numeric( $rel_posts[0] ) ) {
$rel_posts = get_posts( array( 'include' => $rel_posts, 'post_type' => 'any' ) );
}
// Get lowest element
if ( ! is_wp_error( $rel_posts ) && ! empty( $rel_posts ) && is_object( $rel_posts[0] ) ) {
$rel_post = Permalink_Manager_Helper_Functions::get_lowest_element( $rel_posts[0], $rel_posts );
}
}
if ( ! empty( $rel_post->post_type ) ) {
$custom_field_value = Permalink_Manager_Helper_Functions::force_custom_slugs( $rel_post->post_name, $rel_post, false );
}
}
}
}
return $custom_field_value;
}
add_filter( 'permalink_manager_custom_field_value', 'pm_new_permastructure_tag', 3, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment