Jump to content

Automatic Redirect to only post after a query_post with showposts=1 in Wordpress


gabaozin
 Share

Recommended Posts

Hello,

Thanks for reading this.

 

I'm working on a project where the homepage should be a Today's Deal and I'm using the Auto delete posts plugin to move the Today's Deal to the "Previous Deals" Category, after 24 hours.

 

My task is to automatically redirect the homepage to the only post in Today's Deal Category, which will have different permalinks everyday.

 

I'm querring the post with:

<?php query_posts("cat=41&showposts=1"); ?>

 

And I tried redirecting to the result with:

<?php $url = the_permalink(); header("Location: $url"); ?>

 

just after query_posts... but no success.

 

I tried several other things too, apart from searching the web a lot before posting here.

 

Help!

Anyone?

 

Thanks in advance!

Link to comment
Share on other sites

When you say no success what does or does not happen.

 

Are you doing a check to see if there is at least 1 or more posts after your query?

 

So you are saying that the home page will always just display that one post query and never a posts loop...correct?

 

If so try this:

<?php
$url = the_permalink();
echo "<meta http-equiv='refresh' content='0;url=$url'>";//0 is instant, if want delay increase number
exit();//added this for good measure in case more code was to execute
?>

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.