Solved

Wordpress repeat certain post on certain day of the week

Posted on 2014-04-16
5
825 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40005775
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
ID: 40006554
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
ID: 40007336
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
ID: 40007682
Brilliant that worked perfect thanks
0
 
LVL 1

Author Comment

by:niceoneishere
ID: 40007718
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Returning a value from a class function to a partial view in MVC5 7 46
if (is_singular not working 5 39
Wordpress themes CSS? 6 30
MediaWiki - Move a site 4 31
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

756 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