Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:34:40+00:00 2026-06-02T19:34:40+00:00

So I’m starting to write a WordPress theme, and I’m trying to pass some

  • 0

So I’m starting to write a WordPress theme, and I’m trying to pass some variables from The Loop in my index.php to my actual content renderer in content.php.

Due to scope issues, I can’t just create a variable in index.php then try and access it in content.php. The idea of using global makes me shudder, so I thought perhaps I’d tag it onto the $post variable (which is already global). Is this a standard practice? Is there any reason I wouldn’t want to besides accidentally modifying a standard $post member var? Is there a idiomatic WordPress way to do this?

Here is an example of my index.php:

$post->is_n = false; # bad idea?                                
if($post_number === $n){
    $post->is_n = true
}
get_template_part( 'content', get_post_format() );

Then in my content.php:

if($post->is_n){$article_classes .= " is-n";}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:34:41+00:00Added an answer on June 2, 2026 at 7:34 pm

    The $post variable already is a global within WordPress so creating or not creating another global to pass the value would really just be a matter of style more than anything else. WordPress makes pretty extensive use of global values on its own, given its genesis in pre-OOP PHP 4.x days.

    Attaching the value to $post would work, however there’s a chance the $post object won’t be completely destroyed between loop iterations, so your custom property may end up on a later iteration of the $post variable and potentially cause unintended side effects if you are not careful. As well, you’d have to be sure to namespace the property appropriately as to not conflict with future WordPress changes to $post.

    Creating a new global to pass the variable wouldn’t be out of the ordinary within WordPress, attaching custom properties to the $post variable would be a little unusual. If you wanted to namespace things and keep your values out of $_GLOBAL, you could create a quick registry class, but that may be overkill in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.