WordPress.org

Ready to get started?Download WordPress

Forums

Display post by day, month, year filter (3 posts)

  1. writegnj
    Member
    Posted 1 year ago #

    Below code that I added before loop in archive.php doesn't work. However, it works without '&day='.$day. code that I added for viewing posts by day. I have no idea what is wrong with this code. can anyone tell me what to fix? thanks in advance.

    <?php
    wp_get_current_user();
    $loggedin_user_name = $current_user->user_login;

    $year = get_the_time('Y');
    $month = get_the_time('m');
    $day = get_the_time('d');
    query_posts('year='.$year.'&monthnum='.$month.'&day='.$day.'cat=2&posts_per_page='.get_option('posts_per_page').'&author_name='.$loggedin_user_name);
    ?>

  2. writegnj
    Member
    Posted 1 year ago #

    above code displays everything correctly. however, when I click on days in WP default calendar, it does not retrieve posts on the day I clicked.
    Plz help!

  3. writegnj
    Member
    Posted 1 year ago #

    Apparently fixing code to below solved my problem. lol

    <?php
    wp_get_current_user();
    $loggedin_user_name = $current_user->user_login;

    $year = get_the_time('Y');
    $month = get_the_time('m');
    $day = get_the_time('d');

    if ( is_day() ) :
    query_posts('day='.$day.'cat=2&posts_per_page='.get_option('posts_per_page').'&author_name='.$loggedin_user_name);
    elseif ( is_month() ) :
    query_posts('&monthnum='.$month.'cat=2&posts_per_page='.get_option('posts_per_page').'&author_name='.$loggedin_user_name);
    elseif ( is_year() ) :
    query_posts('year='.$year.'cat=2&posts_per_page='.get_option('posts_per_page').'&author_name='.$loggedin_user_name);
    else :
    _e( 'Archives', 'twentytwelve' );
    endif;

    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.