是否可以检索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 db中有数据作为元数据(就像你发布的插件中的代码),你应该能够从任何地方使用它

最新更新