Support » Plugins » Hacks » Display post link for 1 hour

  • Hi,

    Im trying to make a widget to show the upcomming posts by day.
    When a post is posted there will be a live feed on youtube, how can I display that link for one hour on the widget?



Viewing 6 replies - 1 through 6 (of 6 total)

    Below is a modified version of the codex example for getting posts within a date range that should retrieve posts from the last hour

    // Create a new filtering function that will add our where clause to the query
    function filter_where( $where = '' ) {
    	// posts in the last HOUR
    	$where .= " AND post_date > '" . date('Y-m-d-H-i-s', strtotime('-1 hour')) . "'";
    	return $where;
    add_filter( 'posts_where', 'filter_where' );
    $query = new WP_Query( $query_string );
    remove_filter( 'posts_where', 'filter_where' );

    Looks good!
    But what will the query be for in the widget?
    The query must be different then the other posts, only the widget must show the live post.


    Can someone tell me how to use it in the theme?

    if your category you are getting posts from is called youtube-feed then your query string might look like this

    $query = new WP_Query( 'category_name=youtube-feed' );

    note that category_name requires a Category SLUG as input

    if you want to do it by category name instead of slug, then it would be


    so based on the filter code from my last post, you would simply insert the query string code directly before the filter code. This is code that will work by placing it in the php file of the page you are modifying. You can refer to the codex to learn how to display the posts returned by the query. However, if you are actually making a widget, something that will live in widgets.php, then it is more complicated and you can refer to the codex entry on widgets

    and beyond that, google is your friend, which returned this page here

    How To Create Your Own Basic WordPress Widgets

    Hi chilinut,

    The filter wont change the other queries?
    Cause there are 4 other pages with normal queries.


    It should only affect the ones you want. Notice the last 3 lines:

    add_filter( 'posts_where', 'filter_where' );
    $query = new WP_Query( $query_string );
    remove_filter( 'posts_where', 'filter_where' );

    the filter is added, applied to the query you want, then immediately removed!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display post link for 1 hour’ is closed to new replies.