Skip to main content
deleted 2 characters in body
Source Link
Zach Shallbetter
  • 1.2k
  • 7
  • 22
  • 45

I'm working on creating a notification that will indicate when a post is less than a few days old. This is specifically for a custom post type called "news". Is there a way to use global $post; with custom post types?

This is my original code.

<?php global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    if ($days_old < 3) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I tried

<?php 
$post_type = get_post_type();
if (($days_old < 3) && ($post_type == "update""news")) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I'm working on creating a notification that will indicate when a post is less than a few days old. This is specifically for a custom post type called "news". Is there a way to use global $post; with custom post types?

This is my original code.

<?php global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    if ($days_old < 3) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I tried

<?php 
$post_type = get_post_type();
if (($days_old < 3) && ($post_type == "update")) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I'm working on creating a notification that will indicate when a post is less than a few days old. This is specifically for a custom post type called "news". Is there a way to use global $post; with custom post types?

This is my original code.

<?php global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    if ($days_old < 3) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I tried

<?php 
$post_type = get_post_type();
if (($days_old < 3) && ($post_type == "news")) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>
added 59 characters in body
Source Link
Zach Shallbetter
  • 1.2k
  • 7
  • 22
  • 45

I'm working on creating a notification that will indicate when a post is less than a few days old. This is specifically for a custom post type called "news". Is there a way to use global $post; with custom post types?

This is my original code.

<?php global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    if ($days_old < 3) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I tried

<?php 
$post_type = get_post_type();
if (($days_old < 3) && ($post_type == "update")) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I'm working on creating a notification that will indicate when a post is less than a few days old. Is there a way to use global $post; with custom post types?

This is my original code.

<?php global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    if ($days_old < 3) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I tried

<?php 
$post_type = get_post_type();
if (($days_old < 3) && ($post_type == "update")) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I'm working on creating a notification that will indicate when a post is less than a few days old. This is specifically for a custom post type called "news". Is there a way to use global $post; with custom post types?

This is my original code.

<?php global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    if ($days_old < 3) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I tried

<?php 
$post_type = get_post_type();
if (($days_old < 3) && ($post_type == "update")) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>
Source Link
Zach Shallbetter
  • 1.2k
  • 7
  • 22
  • 45

Using global $post; with custom post types

I'm working on creating a notification that will indicate when a post is less than a few days old. Is there a way to use global $post; with custom post types?

This is my original code.

<?php global $post;
    $postdate = str_replace("-", " ",substr($post->post_date, 0,10));
    $postd = explode(" ", $postdate);
    $ageunix = get_the_time('U');
    $days_old_in_seconds = ((time() - $ageunix));
    $days_old = (($days_old_in_seconds/86400));
    if ($days_old < 3) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>

I tried

<?php 
$post_type = get_post_type();
if (($days_old < 3) && ($post_type == "update")) { ?>
    <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#notification").addClass("notification-highlight"); 
        });
    </script>
<?php } ?>