Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

Wordpress repeat certain post on certain day of the week

We have regular specials of the day for our diner. I have created all the 7 posts. I am trying to see if there is a way that for example monday's special can show up on the homepage just on every monday of the month. and tuesday's just on tuesday's and so on.

Thanks and appreciate it
0
niceoneishere
Asked:
niceoneishere
  • 3
  • 2
1 Solution
 
Jason C. LevineNo oneCommented:
So to be clear:

You don't want the post to repost, but instead get sticky for the correct day?
0
 
niceoneishereAuthor Commented:
I just want say french toast with fries special for monday to appear only on every monday on the home page once monday is over tuesday's post should appear on every tuesday

Thanks
0
 
Jason C. LevineNo oneCommented:
Okay, so the way to do it is to use custom fields and then some additional code to figure out which day is current and get the right post.

1) In your posts, create a custom field called "weekday" and give it the value of the day of the week ("Sunday", "Monday", etc).

2) Use the following code to initiate a new WP_Query that pulls the post that matches the current day of the week:


$currentday = date('l');
$query = new WP_Query( array( 'meta_key' => 'weekday', 'meta_value' => $currentday ) );

3) Create a loop on the desired page or template that uses the above to display the matching post.
0
 
niceoneishereAuthor Commented:
Brilliant that worked perfect thanks
0
 
niceoneishereAuthor Commented:
Sorry just one more question how to add an and clause to it can query for day and as well as if its breakfast or lunch for example I tried this but did not work

	     <?php
        $currentday = date('l');
        $query1 = new WP_Query( array( 'meta_key' => 'weekday', 'meta_value' => $currentday && 'meta_key' => 'whatspecial', 'meta_value' => 'Breakfast'  ) );
         ?>
		 <?php if ( $query1->have_posts() ) : ?>
         <?php while ( $query1->have_posts() ) : $query1->the_post(); ?>
         <h2><?php the_title(); ?></h2>
		 <div><?php the_content(); ?></div>
        <?php endwhile; ?>
         <?php wp_reset_postdata(); ?>
        <?php else:  ?>
         <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
         <?php endif; ?>

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now