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 5 years, 1 month ago by
Maciej Bis.
Just to be precise, all the other standard Pods fields (eg. “Plain text”) will work out-of-the-box. The additional snippet is needed only for “Relationship” field.
I assume Toolset needs a snippet as well?
Yes, “Relationship” field is supported out of-the-box only if it set with ACF.
Here is the snippet for Toolset Relationship field:
https://pastebin.com/ZCAx62Ne
Outstanding!
I’m doing a revamp of my website’s design, plus a migration from Drupal 7 to WordPress. Now, for development, I’m using a different domain. My production site is globi[dot]ro, but my development site is set onto globi[dot]site. Note the extension is different, I can’t keep my website offline and I don’t want to use subdomains either. Does it mean that I have to buy a license for two domains? Can we work this out? The .site is just a development domain I’ve bought for this exact reason, nothing else. The .site domain won’t be used for production.
I am writing this here because I’ve used the contact form on the site and there was no answer. Here, on the other hand, you are as helpful as it gets.
Hi @catalinfx,
You can freely use the single domain license for both production & development website.
I have received your message and answered on it – there is a big chance that my email was marked as SPAM.
Bought it just now, thank you very much.
See you on “the other side”! 🙂
Thank you! If you need any further assistance please contact me directly via email – contact /at/ maciejbis.net 😉
As per my initial request, I can confirm the code provided and used within my theme’s functions.php works perfect with Pods. My custom field displays in URL exactly as advertised, using %__my_custom_field_slug%.
This may be marked as solved.
Thank you for the update @catalinfx!