Hi @catalinfx,
Although, Gutenberg is now a default editor, the custom fields functionality and related API works exactly the same. It does not matter if you use Gutenberg or standard editor. The steps explained in the tutorial are still valid.
I have just checked relationship custom field controlled with Pods. The ID of related post is stored as a integer. To make my plugin support “Relationship” field and use a post/page slug instead, you will need a custom snippet. The good news is that the snippet will allow to use specifically use Pods Relationship field also with free version of plugin:
function pm_pods_related_posts_fields($default_uri, $native_slug, $post, $slug, $native_uri) {
global $wpdb;
// Do not change native permalinks
if($native_uri) { return $default_uri; }
// Use it only if PodsAPI class is available
if(!function_exists('pods_api')) { return $default_uri; }
// Use it only when custom fields tags are present in the permastructure settings
if(strpos($default_uri, "%__") === false) { return $default_uri; }
// OPTIONAL: Use it only for specific post types
// if(empty($post->post_type) && !in_array($post->post_type, array('car'))) { return $default_uri; }
// Get Pod
$pod = pods($post->post_type, $post->ID);
if(!empty($pod)) {
$pods_relationship_fields = array_keys($pod->fields());
foreach($pods_relationship_fields as $field) {
if(strpos($default_uri, "%__{$field}%") === false) { continue; }
// Get related post
$related = $pod->field($field);
if(!empty($related['ID'])) {
$related_post = get_post($related['ID']);
$default_uri = str_replace("%__{$field}%", $related_post->post_name, $default_uri);
}
}
}
return $default_uri;
}
add_filter('permalink_manager_filter_default_post_uri', 'pm_pods_related_posts_fields', 5, 5);
-
This reply was modified 3 years, 10 months ago by
Maciej Bis.