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 7641927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:03:26+00:00 2026-05-31T09:03:26+00:00

* edit have fixed this code – see inline comments marked EDIT * I’m

  • 0

*edit have fixed this code – see inline comments marked EDIT *

I’m getting a few PHP debug notices when using the following code in a wordpress theme. It’s my first attempt at using a PHP class, and it does work ok, but the debug notices concern me. I am calling the method in my PHP template thus:

<?php $getjobmeta->job_type(); ?> & <?php $getjobmeta->post_types(); ?>

The debug notices are as follows:

Notice: Undefined variable: post

Notice: Trying to get property of non-object

From the research I have done this looks like an issue with the class sometimes returning a non object, so i tried wrapping the ‘echo’ in isset and is_object but I just can’t fix those notices.

Here is the simplified code. For the sake of my sanity I could really use some help.

    // define the class

class getJobMeta { 

    var $jobmeta_echo; // set a class variable to store our echo

    public function job_type() { // define a class function and make it public

            global $post // EDIT IN FIX

          if ( 'post' == get_post_type() )  {       
                   $jobtype = get_the_term_list( $post->ID, 'job-type', '<span itemprop="employmentType">', ', ', '</span>', 0 ); // 0 at end of arg signifies that we don't want links outputted
                   }

          else { 
                    return ''; 
               }

     echo $jobtype.$this->jobmeta_echo;

     } // end function job_type

    // define post type


  public function post_types() { 

               global $post // EDIT IN FIX


        if ('post' == get_post_type())  {
                    $posttype = get_the_term_list( $post->ID, 'channel', '<strong class="channel-links clearfix">', ', ', '</strong>', 1); // 1 means output as link

            } elseif ( 'blog' == get_post_type() )  {
                $posttype = '<a href="/blog/" class="post-type-label">Blog</a>';

            } elseif ( 'type2' == get_post_type() )  {
                $posttype = '<a href="/type2/" class="post-type-label">Type2</a>';

        } else {
                $posttype = '';
        }


    echo $posttype.$this->jobmeta_echo;  // EDIT TYPO


    } // end function posttype


   } // end getJobMeta class

    // set the class into a variable
    $getjobmeta = new getJobMeta; 

Thanks
Ben

  • 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-05-31T09:03:27+00:00Added an answer on May 31, 2026 at 9:03 am

    You’re asking about WordPress here and $post is a global variable so you need to define it within your functions:

    public function job_type() {
        global $post;
        ...
    
    public function post_types() { 
        global $post;
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT : As of 2012-06-11 this bug has been finally fixed! https://bugs.webkit.org/show_bug.cgi?id=35981#c1 I have
EDIT: I have fixed all but two warnings now, so thank you all for
EDIT i have something like this in a file: imagecolor=0 arrayimagecolorcopy=0 arrayimagecolorcopy3d=0 when i
I'm using NHibernate Search for NHibernate 3.0 GA. I have this code in my
I have created a file and saved it as UTF-8 I placed this code:
i have fixed height and width of the edit text. When i start typing
EDIT Due to the overwhelming amount of advice I have received, I have fixed
I have an activity that extends MapActivity, and inside onCreate() I have this code
EDIT: Mozilla fixed the bug. This thread is dead. EDIT: This is a Mozilla
Edit: fixed several syntax and consistency issues to make the code a little more

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.