Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

LittleBigThing on "display 'activities' custom post type odered by activity date"

$
0
0

Hi,

I am using the following code to display my custom post type 'activities'. It works and displays them ordered by activity date (meta data) and only the future (and today) activities are displayed:

$yesterday = time() - 86400;

$args = array(
'post_type' => 'activities',
'posts_per_page' => -1,
'meta_key' => 'date_activity',
'orderby' => 'meta_value_num',
'order'	=> 'ASC'
);
$act_query = new WP_Query( $args );

if ( $act_query->have_posts() ) : ?>
<?php while ( $act_query->have_posts() ) : $act_query->the_post(); ?>

<?php $activity_date = get_post_meta( $post->ID, 'date_activity', true );

if ( $activity_date > $yesterday ) : ?>

<?php get_template_part( 'content', 'activities' ); ?>

<?php endif; ?>

<?php endwhile; ?>

<?php wp_reset_postdata(); ?>

<?php endif; ?>

It works but I cannot really use paging and 'posts_per_page' directly on it since it extracts all posts: also the older ones, it only won't display them. I found a possible solution using meta_compare but I won't get it working like this:

$yesterday = time() - 86400;

$args = array(
'post_type' => 'activities',
'posts_per_page' => -1,
'meta_key' => 'date_activity',
'meta_value' => $yesterday,
'meta_compare' => '>'
'orderby' => 'meta_value_num',
'order'	=> 'ASC'
);
$act_query = new WP_Query( $args );

if ( $act_query->have_posts() ) : ?>
<?php while ( $act_query->have_posts() ) : $act_query->the_post(); ?>

<?php get_template_part( 'content', 'activities' ); ?>

<?php endwhile; ?>

<?php wp_reset_postdata(); ?>

<?php endif; ?>

Anyone any idea why it won't work? It displays actually all 'activities' for some reason...
Thanks a lot!


Viewing all articles
Browse latest Browse all 8245

Trending Articles