过滤Wordpress插件开发中的自定义字段

时间:2021-09-16 17:12:30

I'm wondering if it's possible to add filters and actions on Custom Fields in a post?

我想知道是否可以在帖子中的自定义字段中添加过滤器和操作?

I have a plugin that extracts all <a> tags and converts them into trackable objects. This works great for the content and excerpt but I can't figure out how to filter the Custom Fields.

我有一个插件,它提取所有标签并将它们转换为可跟踪的对象。这对于内容和摘录非常有用,但我无法弄清楚如何过滤自定义字段。

I've tried calling the below:

我试过调用以下内容:

add_filter('the_meta', 'function_name', $priority)

which I read should work but it doesn't seem to do anything.

我读过的应该可以工作,但它似乎没有做任何事情。

Any help would be appreciated.

任何帮助,将不胜感激。

1 个解决方案

#1


The code you've shown adds a filter to a hook that doesn't exist within the default installation of wordpress. Are you trying to get your function to execute within the the_meta function in wp-includes/post-template.php? If so, then you need to attach your filter to the the_meta_key hook. Your code should then read:

您显示的代码会向一个挂钩添加一个过滤器,该挂钩在wordpress的默认安装中不存在。您是否尝试在wp-includes / post-template.php中的the_meta函数中执行函数?如果是这样,那么您需要将过滤器附加到the_meta_key挂钩。您的代码应该是:

add_filter('the_meta_key', 'function_name', $priority)

If this is not the function you want, then you'll have to add an apply_filters function call to run your custom filter.

如果这不是您想要的功能,那么您必须添加apply_filters函数调用来运行自定义过滤器。

#1


The code you've shown adds a filter to a hook that doesn't exist within the default installation of wordpress. Are you trying to get your function to execute within the the_meta function in wp-includes/post-template.php? If so, then you need to attach your filter to the the_meta_key hook. Your code should then read:

您显示的代码会向一个挂钩添加一个过滤器,该挂钩在wordpress的默认安装中不存在。您是否尝试在wp-includes / post-template.php中的the_meta函数中执行函数?如果是这样,那么您需要将过滤器附加到the_meta_key挂钩。您的代码应该是:

add_filter('the_meta_key', 'function_name', $priority)

If this is not the function you want, then you'll have to add an apply_filters function call to run your custom filter.

如果这不是您想要的功能,那么您必须添加apply_filters函数调用来运行自定义过滤器。