Hello, Thanks for reading this. I'm working on a project in Wordpress 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!
In wordpress if you use header to redirect then it will throw error. you have to use wordpress built in redirection function wp_redirect. and you have put the redirect code like this: ob_start(); wp_redirect(URL); ob_flush(); ob_end(); so it will redirect properly..
Hi cerahil, Thank you so much for the prompt reply! In fact, I managed to redirect correctly using regular "header: Location" by putting it at the very beggining of the page and adding exit(); after the code. I tried your code and it worked as well. It redirects properly to a simple URL. However, what I CANNOT figure out is how to make it redirect to the post, result of the previous function (query_post). the_permalink() will result in a white page with the right URL showing in the body of the page. I would need the browser to GO to that page instead of echo it. Current code is: <?php query_posts("cat=41&showposts=1"); ?> <?php $url = the_permalink(); ?> <?php ob_start(); wp_redirect("$url"); ob_flush(); ob_end(); ?> THANKS A MILLION!
As I said, I can't put the POST_ID since everyday it will be different. The solution for that is not simple, but here it is: <?php query_posts("cat=41&showposts=1&orderby=rand"); While(have_posts()) : the_post(); $pid = $post->ID; Endwhile; $url = get_permalink($pid); Echo '<script>location.href="'.$url.'"</script>'; ?> Thanks for everyone that tried helping me. Cheers!