Forum Moderators: coopster
I have this piece of wordpress code which does something if the user is logged in and has at least one post:
<?php if ( is_user_logged_in()) : ?>
<?php if(get_usernumposts(wp_get_current_user()->ID) > 0) : ?>
DO SOMETHING
<?php endif; ?>
<?php endif; ?>
When users arrive at my homepgae I would like to:
a) If they meet the above conditions redirect them to a specific page
b) If they don't meet the above conditions leave them on the home page.
I would like it so that users are only redirected when they initally arrive on the homepage ie. if they navigate back to the home page from another page within my site they shouldn't be redirected again (only if arriving from an external location)
Is this possible? If so, does anyone know how to do this?
Thanks!
if(is_user_logged_in() && (get_usernumposts(wp_get_current_user()->ID) > 0))
{
header('Location: http://www.example.com/good.php');
exit;
} else {
header('Location: http://www.example.com');
exit;
}
Something like that should do the trick. :)
<?php
if(is_user_logged_in() && (get_usernumposts(wp_get_current_user()->ID) > 0) && is_home())
{
header('Location: http://example.com');
exit;
}
?>
I would like to replace http://example.com with a url which gets output using this code:
<?php $numposts = get_posts('sort_column=menu_order&numberposts=-1'); ?>
<?php foreach ($numposts as $numpost) {
if($numpost->post_author == wp_get_current_user()->ID) {
echo get_page_link($numpost->ID);
}
}
?>
How would I go about doing this?
Thanks.
$numposts = get_posts('sort_column=menu_order&numberposts=-1');
foreach ($numposts as $numpost)
{
if($numpost->post_author == wp_get_current_user()->ID)
{
header('Location: ' . urlencode(get_page_link($numpost->ID)));
exit;
}
}