是否可以检索Wordpress中插件中定义的自定义字段的值?

时间:2015-07-21 00:17:42

标签: wordpress custom-fields

我想修改一个无效的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”字段是在插件中定义的,而不是在主题的函数文件中。有没有办法检索插件中定义的自定义字段,而不是在主题的函数文件中?

谢谢。

1 个答案:

答案 0 :(得分:0)

不确定它会有所帮助,但尝试使用此插件https://wordpress.org/plugins/advanced-custom-fields/,我认为它可以帮助您使用其他插件中的自定义字段。

或者您可以一步一步地按照文档https://codex.wordpress.org/Custom_Fields

进行操作

如果自定义字段将wordpress db中的数据作为元数据(就像您发布的插件中的代码一样),您应该可以在任何地方使用它。