• Resolved mlinhuberin

    (@mlinhuberin)


    Hi there,

    in my site the some posts are used to announce future events. The post datum is the vent datum. I show the posts at the front page and in the archive using

    $the_query = new WP_Query('showposts=-1&post_type=post&post_status=future,publish&orderby=date&order=ASC&cat='.$cat);

    But if I choose a future post to show the details I become a 404. I tried
    $the_query = new WP_Query( 'post_status=future,publish' );
    but then all posts in the categorie are shown.

    where is my mistake?

    Thank you
    Marion

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author Tomas Mackevicius

    (@tomasm)

    There are several plugins for that:

    https://ww.wp.xz.cn/plugins/future/

    In one of my project I was using this hard coded solution. It was based on Twenty Ten theme. In index.php I modified loop to:

    <div id="container">
    
    			<div id="content" role="main">
    
    						<!-- Constructing new custom LOOP outside the main LOOP -->
    
    						<?php /* Adding filter to show posts for today and future */ ?>
    						<?php add_filter( 'posts_where', 'my_posts_where_from_today' ); ?>
    
    						<?php query_posts( array( 'category_name' => 'naujienos', 'post_status' => 'future || publish', 'post_type' => 'post', 'post_per_page' => '15', 'orderby' => 'date', 'order' => 'ASC' ) ); ?>
    						<?php while ( have_posts() ) : the_post(); ?>
    
    						<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    						<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
    [...]

    Then this functions goes to functions.php:

    //Show posts for today and future
    function my_posts_where_from_today( $where = '' ) {
    	$where .= " AND post_date > '" . date('Y-m-d', strtotime('now')) . "'";
    	return $where;
    }
    
    /* Show future posts on single posts and pages*/
    function show_future_posts($posts)
    {
       global $wp_query, $wpdb;
       if(is_single() && $wp_query->post_count == 0)
       {
          $posts = $wpdb->get_results($wp_query->request);
       }
       return $posts;
    }
    add_filter('the_posts', 'show_future_posts');
    Thread Starter mlinhuberin

    (@mlinhuberin)

    Thank you very much, you made my saturday night 😉 – the Plugin works good!

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

The topic ‘show future posts’ is closed to new replies.