简体   繁体   English

将变量从一个文件传递到WordPress中的另一个文件

[英]Pass a Variable from one file to another in WordPress

I have added a custom field in a post (wp-themes/template/modal-question.php) like this 我在这样的帖子(wp-themes / template / modal-question.php)中添加了一个自定义字段

<input type="checkbox" name="anonymous" value="true"> 
<span><?php _e('Go Anonymous', ET_DOMAIN); ?></span>

and variable is 而变量是

<?php if(isset($_POST['anonymous1']))
{ $post_author = 3; echo $post_author; } 
?>

I need to pass this varible ' $post_author ' ( $_GET or $_POST ) into another file post.php (Insert query into DB file), which resides in wp-includes/post.php 我需要将此变量' $post_author '( $_GET$_POST )传递到另一个文件post.php(将查询插入到DB文件中),该文件位于wp-includes / post.php中

Please let me know if there's a way to do it. 请让我知道是否有办法。

Thanks in advance. 提前致谢。

Here you go: 干得好:

One time create this: 一次创建此:

$GLOBALS['anonymous1'] = 'Your Value';

Then you get in any template of WordPress 然后您进入任何WordPress模板

echo $GLOBALS['anonymous1'];

Edit: 编辑:

<?php 
if(isset($_POST['anonymous1'])) { 
  $GLOBALS['anonymous2'] = $_POST['anonymous1'];
  echo $GLOBALS['anonymous2'];
} 
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM