0

I have a WordPress website and have some posts. I have some special post under category "Blessing". I want to display all post from blessing category which were posted on current week though a anchor tag. I want place one photo on homepage When user will click on that it will only show the posts from Blessing category of current week. year can be any... means it year is not necessary, I want only post of the current week.. please help.. coding will be helpful... I am new to WordPress... Please help.

I have type some code... please help.. It is showing the post of week.. but all not from my category

<?php
$week = date('W');
$args = array(
'w' => $week,
'post_type' => 'post',
'post_status' => 'publish',
'cat' => 'blessing',
'date_query' => array('week' => $current_week),
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php
  endwhile;

wp_reset_query();  // Restore global post data stomped by the_post().
?>
Pandit Ji
  • 13
  • 7

1 Answers1

0

you need to use date() function (PHP DATE);

$current week = date("W");

//$current_week will output number of current week

Then u do post query, from wordpress 3.7 u can use "date_query" (WP_QUERY#Date_parameters);

query_posts(array(
'cat' => 'Blessing', // chosing category
'date_query' => array('week' => $current_week), // choosing date range
'posts_per_page' => '-1'// outputs all posts
));
while (have_posts()) : the_post();
//here goes your loop
endwhile;

Use it in your template file. And dont forget to put wp_reset_query(); after your query is done, and if you have loops after.

If u are using wordpress under 3.7, u can use this answer : Wordpress - get posts by date range, but here u need to get first and last date from current week (u can use this Finding First day of week via php [duplicate]). Have a nice day.

Community
  • 1
  • 1
  • Thanks for the code and reply.. i have type some code in my above question. It is showing the weekly posts by category not working... please help... And i am using wordpress 3.8.3 – Pandit Ji Jul 30 '14 at 05:05