WordPress.org

Ready to get started?Download WordPress

Forums

how to show only today's posts (5 posts)

  1. fzishk
    Member
    Posted 1 year ago #

    i have several cat in my website ! in each category i m calling 4 posts, but i want call only today's post in every cat, plz help ?

    my Code is :

    <?php
    
    //The Query
    $query = new WP_Query( 'category_name=small International News&posts_per_page=4&offset=1' );
    
    echo '<ul>';
     //The Loop
    while ( $query->have_posts() ) : $query->the_post();
    	echo '<li>';
    	$queried_post = get_post($cat_id); ?>
    	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
    	<h1><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    	<?php echo '</li>';
    endwhile;
    echo '</ul>';
    	?>
  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

  3. fzishk
    Member
    Posted 1 year ago #

    i used that Query but its not working ,i m not gud in Php so can you tell me where i have to use that time Query ?

    <?php
    //The Query
    $today = getdate();
    $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] );
    $query = new WP_Query( 'category_name=small-Business News&posts_per_page=4&offset=1' );
    
    echo '<ul>';
     //The Loop
    while ( $query->have_posts() ) : $query->the_post();
    	echo '<li>';
    	 ?>
    	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
    	<h1><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    	<?php echo '</li>';
    endwhile;
    echo '</ul>';
    
    	?>
  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    only use one query - combine the parameters;

    try:

    $query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"] . '&category_name=small-business-news&posts_per_page=4&offset=1' );

    important: check the category_name which needs to be the slug of the one category you want to show (I changed it above, but this is just a guess)

  5. fzishk
    Member
    Posted 1 year ago #

    thnx alot Problem Solved :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags