是否可以检索 Wordpress 插件中定义的自定义字段的值?
Is it possible to retrieve the value of custom fields defined in a plugin in Wordpress?
我想修改一个无法正常工作的 WordPress 插件。
也就是说,
function append_query_string($url) {
global $post;
if ( get_post_meta($post->ID, 'inm_la_title_url', true) ) {
if ( get_post_meta($post->ID, 'inm_la_new', true) ) {
$link = get_post_meta($post->ID, 'inm_la_title_url', true) . '" target="_blank';
} else {
$link = get_post_meta($post->ID, 'inm_la_title_url', true);
}
} else {
$link = $url;
}
return $link;
}
插件文件包含上述代码。但它有一个问题,我想使用这个插件中定义的自定义字段 "inm_la_new"。
我尝试在 index.php 文件中使用以下代码:
<?php
if ( get_post_meta($post->ID, 'inm_la_new', true) ) {
echo '" target="_blank';
}
?>
但是,它在 index.php 文件中不起作用。我认为这是因为 "inm_la_new" 字段是在插件中定义的,而不是在主题的函数文件中。有没有办法检索在插件中定义的自定义字段而不是在主题的函数文件中?
谢谢。
不确定它是否有帮助,但请尝试使用此插件 https://wordpress.org/plugins/advanced-custom-fields/,我认为它会帮助您使用其他插件的自定义字段。
或者您可以按照文档一步步进行https://codex.wordpress.org/Custom_Fields
如果自定义字段在 wordpress 数据库中有数据作为元数据(比如您发布的插件中的代码),您应该可以在任何地方使用它。
我想修改一个无法正常工作的 WordPress 插件。 也就是说,
function append_query_string($url) {
global $post;
if ( get_post_meta($post->ID, 'inm_la_title_url', true) ) {
if ( get_post_meta($post->ID, 'inm_la_new', true) ) {
$link = get_post_meta($post->ID, 'inm_la_title_url', true) . '" target="_blank';
} else {
$link = get_post_meta($post->ID, 'inm_la_title_url', true);
}
} else {
$link = $url;
}
return $link;
}
插件文件包含上述代码。但它有一个问题,我想使用这个插件中定义的自定义字段 "inm_la_new"。
我尝试在 index.php 文件中使用以下代码:
<?php
if ( get_post_meta($post->ID, 'inm_la_new', true) ) {
echo '" target="_blank';
}
?>
但是,它在 index.php 文件中不起作用。我认为这是因为 "inm_la_new" 字段是在插件中定义的,而不是在主题的函数文件中。有没有办法检索在插件中定义的自定义字段而不是在主题的函数文件中?
谢谢。
不确定它是否有帮助,但请尝试使用此插件 https://wordpress.org/plugins/advanced-custom-fields/,我认为它会帮助您使用其他插件的自定义字段。
或者您可以按照文档一步步进行https://codex.wordpress.org/Custom_Fields
如果自定义字段在 wordpress 数据库中有数据作为元数据(比如您发布的插件中的代码),您应该可以在任何地方使用它。