human_time_difference()
will not work here as it returns a string in a human readable form. However, we can use some of the logic used there to construct a workable function
You can try the following: (Untested)
function get_custom__time_diff()
{
global $post;
// Get the current time
$current_time = time();
// Get the post date
$post_date = get_the_time( 'U', $post );
// Get the amount of seconds in 5 hours
$test_time = 5*HOUR_IN_SECONDS;
$diff = $current_time - $post_date;
if ( $diff < $test_time )
return 'New';
return '';
}
You can then call it as follow inside the loop
echo get_custom__time_diff();
Related Posts:
- Error Warning: Declaration of description_walker::start_el after PHP upgrade [duplicate]
- Mega Menu Walker
- Autoloading in Child Theme
- How to add a class to the attachment images
- How to call a function only once (global variable scope)
- Multiple is_page() in page.php
- Fatal error: Call to undefined function plugin_dir_path()
- Switching wp_get_sites to get_sites
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- How to correct schedule my event weekly with wp_schedule_event()
- Execute a shortcode when clicking on a image
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- How can update custom meta for all posts
- Is $hook a global variable in WordPress
- Change logo based on incoming domain
- wrong php date()?
- How do I fetch all comments per post via WP REST API?
- Shortcode content output but not in correct place
- PHP code inside shortcodes
- How do I display a user’s previous orders as a select box option on a product?
- Remove meta description on certain pages
- Image media upload metabox
- How to combine wordpress_logged_in cookies in one cookie?
- Two Different Links for Same Product – WooCommerce [closed]
- Automatically adding new post categories to menu
- Get post id in a function when edit/add a post
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- get author_name from queried post
- Pass php dynamic variable to shortcode
- Limit 1 global comment per minute
- Modify custom field input data before creating a new post
- Query Pages and post excerpts dynamically
- Is there a way to conditionally check whether a WordPress post title is empty?
- Echo a function inside a function
- Use WordPress function in php file
- Get my site session in wordpress?
- wp_force_remove_style’ not found
- is_user_logged_in() not working in AJAX validation call
- Register a menu – Error Header
- Creating WordPress Shortcode with Variable
- Convert the_permalink() function output into string
- Add meta tags to a custom header
- Need php code’s output to display underneath a Divi Module
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- get_current_site() is undefined
- How to use mysql LIKE with wpdb?
- woocommerce related product title length
- Automatically Add Page Links to Nav Menu
- blank white page when post/update/change option etc
- Function sanitize_title() does not appear to be working
- Query for user roles
- writing an unique php function to be used on my website
- Displaying Event within two given time frames
- How to prevent a function from running based on host (ie web vs local)?
- How to call custom function outside from the admin page?
- Is there a way to create a “copy post” link?
- Use of antispambot with $curauth->email
- How to change the author box selection on a post to a custom taxonomy
- Output product category link from WP_Query
- Adding onload to body for certain pages
- Delete images from media library when user deletes an image from ACF Gallery
- Reject all malicious URL requests functions.php
- How to send a php var to jQuery Ajax call with two different file
- Change wordpress’ database data using ajax – how to get current user id?
- Best way to use variables in multiple functions?
- Notice: Undefined variable
- Cannot fetch posts with certain ‘product_cat’. WP_Query is empty
- How to override WooCommerce Order Item Meta with data from Cart?
- Taxonomy Child Term, Counter is staying on 0
- Access to “My Site” is missing from the admin bar
- How to redirect (301) trashed post to it’s parent taxonomy TERM ARCHIVE instead of 404 page
- Detect what link user clicks and Redirect to a specific page for logged in users only
- Offset with ajax load more posts duplicates
- Need help with PHP functions
- Using get_theme_mod with checkbox to display content
- WordPress styling recent post
- Styling admin page rows in order of importance (checkboxes)
- Insert wordpress tags below posts via functions.php
- Break a WordPress function to run in patches and re-continue
- Pagenav Not appearing on custom Template
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Highlight posts currently being edited on multiple editor site?
- My title is showing after the shortcode
- Load a Header in wordpress
- Trouble figuring out how to get my button to submit comment
- Shortcode to include PHP file, pass various parameters to include?
- Why can’t I include echo inside a variable? [closed]
- Adding multiple conditional tags in a function?
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- How do I change the Go To Categories link in the term_updated_messages
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- Understanding responsive imagery
- Why a class property becomes empty?
- Hide category by tag
- How to get meta box labels?
- How do I stylize selected comments?
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico