Solved

Wordpress repeat certain post on certain day of the week

Posted on 2014-04-16
5
780 Views
Last Modified: 2014-04-17
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
Comment
Question by:niceoneishere
  • 3
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
So to be clear:

You don't want the post to repost, but instead get sticky for the correct day?
0
 
LVL 1

Author Comment

by:niceoneishere
Comment Utility
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
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
Comment Utility
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
 
LVL 1

Author Closing Comment

by:niceoneishere
Comment Utility
Brilliant that worked perfect thanks
0
 
LVL 1

Author Comment

by:niceoneishere
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now