athlan / wordpress-custom-fields-permalink-plugin

Plugin allows to use post's custom fields values in permalink structure by adding %field_fieldname%, for posts, pages and custom post types.
http://athlan.pl/wordpres-custom-fields-permalink-plugin/
MIT License
41 stars 9 forks source link

Getting Concatenated Field Value in Permalinks #43

Open puremana opened 5 years ago

puremana commented 5 years ago

We are having an issue where some of the generated permalinks are having the custom locale field concatenated.

Permalinks Settings Code /%field_locale%/%postname%/

Custom Locale Field Value image

Expected image

Reality image

We are on version 2.0.

This is very inconsistent and rarely happens. The affected locales seem different each time too.

I hope this is enough information to diagnose the problem, happy to provide more if needed

athlan commented 5 years ago

Hello, thanks for contact. Could you please check in the database, whether your custom field locale for thi particular post does not have multiple en-ca values?

puremana commented 5 years ago

Yes, I found that if I create a duplicate locale value in the wpdb_postmeta table it concatenates them

image

image

athlan commented 5 years ago

That' the issue. Plugin concatenates duplicated values by default.

If you want to have the single value, you can:

puremana commented 5 years ago

I can't see any way to format a text field to only show one value, would you be open to a pull request to fix this?

athlan commented 5 years ago

Hello,

It's already supported in plugin. wpcfp_get_post_metadata filter should do a trick for you. You'll receive all post params and then you can assign the single one to array key which will be used.

But anyway, it's little strange that you're facing such issue, because plugin should take the very first value of meta field, we have even test for that.

  1. Could you also pase here output of
    var_dump(get_post_meta($post->ID)));

    of your case?

  2. Could you share permalink structure?
puremana commented 5 years ago
  1. image

Which resulted in image

I can't get that output currently, but tomorrow I should be able to

puremana commented 5 years ago

Different recipe, same issue, here's the var_dump output

image

puremana commented 5 years ago

@athlan If the plugin is supposed to take the first value, doesn't this make it a bug?