0

What is the php code for showing post date on the page?

For example, it is a woocommerce product and here is the php code that I have so far:

does this work?

   if ($hide_price !== '0') :
        $output .= '<div class="mywoocmmerceprice>';
        $output .= $product->get_categories();  
//here is where I want to add the date                          
        $output .= '</div>';
   endif;

Thank you

0

the_date() is technically the template tag to do it. However it has a somewhat unusual aspect to only output once per date, so if there are multiple posts on page from same date they won't all show it.

get_the_date() is one level lower and retrieves (not outputs) a post's date without that bit of logic.

  • Thank you for the explanation. Luckily, there will be only one post (or product) per page, and so I think the_date() will work. Would the following work? $output .= $post->get_the_date(); – steve Kim Feb 23 '15 at 9:08
  • No, it's a function rather than property of object. It should work in a normal WordPress Loop. Since you are using WooCommerce product you might need to handle it differently, that would be up to specifics of the plugin. – Rarst Feb 23 '15 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.