• Resolved catalinfx

    (@catalinfx)


    Sorry, but I feel obliged to open this topic once more.

    I’m not sure I can use custom fields in URLs. Your tutorials are obsolete. I know I have to buy the PRO version, but I rather keep my money till you explain how this actually works. The last tutorial on this is pretty old, pre-Gutenberg era. Lots have changed.

    I have several custom post types and several custom fields. Can we use custom fields out of the box? I am using PODS and relationship custom fields between custom post types.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Maciej Bis

    (@mbis)

    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.
    Plugin Author Maciej Bis

    (@mbis)

    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.

    Thread Starter catalinfx

    (@catalinfx)

    I assume Toolset needs a snippet as well?

    Plugin Author Maciej Bis

    (@mbis)

    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

    Thread Starter catalinfx

    (@catalinfx)

    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.

    Plugin Author Maciej Bis

    (@mbis)

    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.

    Thread Starter catalinfx

    (@catalinfx)

    Bought it just now, thank you very much.

    See you on “the other side”! ??

    Plugin Author Maciej Bis

    (@mbis)

    Thank you! If you need any further assistance please contact me directly via email – contact /at/ maciejbis.net ??

    Thread Starter catalinfx

    (@catalinfx)

    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.

    Plugin Author Maciej Bis

    (@mbis)

    Thank you for the update @catalinfx!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Custom fields in URL’ is closed to new replies.