Support » Fixing WordPress » Display post by day, month, year filter

  • 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);
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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!

    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;

    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display post by day, month, year filter’ is closed to new replies.