jeudi 14 mai 2015

if statement based on date paramater

I have a wordpress query that gets posts from a custom post type. The posts have a custom meta date field. I would like to put posts that have a dat in the future in a table called "Ongoing" (this part is complete and appears to work well). I would like to put posts with a date in the past in a table called "published". This is where I am having problems as the if statement seems to show posts even if they have a date that is in the future. I am using if completion date is equal to or greater than start of time, now. for the ongoing posts. I am using the opposite for the published posts with. Seeing as it is the same but inverted, I don't get why the query pulls in posts from a future date.

What am I doing wrong?

Much thanks in advance


ONGOING - working

<?php $wp_query_ongoing = new WP_Query( array( 'post_type' => 'research', 'posts_per_page' => 5, 'order' => 'asc' ) ); ?>
            <?php while ( $wp_query_ongoing->have_posts() ) : $wp_query_ongoing->the_post(); //start of the loop ?>

        <?php
            $post_id = get_the_ID();
            $completion_date = get_post_meta( $post_id, "duration_end", true );
            $publication_date = get_post_meta( $post_id,  "publication_date", true );
        ?>
            <?php if (strtotime($publication_date) >= strtotime("now") || strtotime($completion_date) >= strtotime("now")) { ?>
            <tr>
                <td><?php echo do_shortcode('[wpuf-meta name="_hidden_type"]' ); ?></td>
                <td><?php the_title(); ?></td>
    ...
                <td>
                    <?php echo do_shortcode('[wpuf-meta name="duration_end"]'); ?>
                    <?php echo do_shortcode('[wpuf-meta name="publication_date"]'); ?>
                </td>
            </tr>

            <?php } ?>

        <?php endwhile; //end of the loop ?>

PUBLISHED - not working

<?php $wp_query_published = new WP_Query( array( 'post_type' => 'research', 'posts_per_page' => 5, 'order' => 'asc' ) ); ?>
        <?php while ( $wp_query_published->have_posts() ) : $wp_query_published->the_post(); //start of the loop ?>

        <?php
            $post_id = get_the_ID();
            $completion_date = get_post_meta( $post_id, "duration_end", true );
            $publication_date = get_post_meta( $post_id,  "publication_date", true );
        ?>
            <?php if ( strtotime($publication_date) <= strtotime("now") || strtotime($completion_date) <= strtotime("now")){ ?>

<td>
                    <?php echo do_shortcode('[wpuf-meta name="duration_end"]'); ?>
                    <?php echo do_shortcode('[wpuf-meta name="publication_date"]'); ?>
                </td>
<?php } ?>

        <?php endwhile; //end of the loop ?>

Aucun commentaire:

Enregistrer un commentaire