Développeur Freelance à Lyon

Développement PHP, Wordpress, Laravel
Intégration CSS, responsive design
Applications iOS, Android

WordPress : get_post_meta(‘date’) returns the post date

Sometimes, I am lazy, and I set post meta with very simple meta keys, like “date”.

It works like a charm, but today on my client’s website, the very classic “get_post_meta(ID, ‘date’, true)” do not return my meta, but the post date!

After several hours of investigation, I found the guilty plugin : Pods !

In a recent update (I guess) Pods decided to return the post date when you query a post meta with the name “date” !

Luckily, I found a filter in the plugin to disable this strange behaviour, in fact, you can decide which metas Pods cannot replace. It is as simple as this filter :

add_filter( 'pods_meta_keys_not_covered',  'my_pods_meta_keys_not_covered', 10, 2);

function my_pods_meta_keys_not_covered($keys_not_covered, $type)
{
	
	if( $type == 'post_type')
	{
		$keys_not_covered[$type]['date'] = true;
	}
	
	return $keys_not_covered;	
}

You can change the meta key, or add others, in my case this is only the meta with the key ‘date’ for the post_type ‘post’.

TIPS : Pods replaces the post_type passed in the arguments by ‘post_type’ for the type ‘post’

Leave a Reply

Your email address will not be published. Required fields are marked *