Skip to content

Quick fix for where a meta tag is duplicate #7

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
arnonzamir opened this issue Dec 23, 2017 · 3 comments
Closed

Quick fix for where a meta tag is duplicate #7

arnonzamir opened this issue Dec 23, 2017 · 3 comments
Assignees
Labels

Comments

@arnonzamir
Copy link

arnonzamir commented Dec 23, 2017

Great plugin. Slick and functional.

I had a website with some post that have duplicate meta tags with similar keys. Strange and unwanted, but it was there.
It may be useful for someone so here's my quick-fix:

public static function linkRewriteFieldsExtract($post, $fieldName) {
        $postMeta = get_post_meta($post->ID);
        if(!isset($postMeta[$fieldName]))
            return '';	

	//deal with duplicate keys by taking the value of the first
        if (is_array($postMeta[$fieldName])) {
			$value =  $postMeta[$fieldName][0];	
		} else {
			$value = implode('', $postMeta[$fieldName]);
        }
        $value = sanitize_title($value);
        return $value;
    }
@athlan
Copy link
Owner

athlan commented Dec 26, 2017

Hello,

Thank you for the contribution. Indeed, it is an another case I didn’t considered. Soon I will review code and make some tests and release a new version.

@athlan athlan self-assigned this Dec 26, 2017
@athlan athlan added the bug label Dec 26, 2017
@athlan
Copy link
Owner

athlan commented Mar 22, 2018

@arnonzamir the fix is proposed. Please look at the test suite with expected behavior. Code under PR #9

@athlan
Copy link
Owner

athlan commented Mar 26, 2018

Fixed.

@athlan athlan closed this as completed Mar 26, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants