Vijay Bhaskar
Vijay Bhaskar

Reputation: 3

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

<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

Please let me know if there's a way to do it.

Thanks in advance.

Upvotes: 0

Views: 2659

Answers (1)

Noman
Noman

Reputation: 1487

Here you go:

One time create this:

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

Then you get in any template of WordPress

echo $GLOBALS['anonymous1'];

Edit:

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

Upvotes: 1

Related Questions