You should be able to use some combination of count_user_posts() and wp_redirect() to achieve this functionality. Something like this:
if ( 0 == count_user_posts( get_current_user_id() ) ) {
wp_redirect( get_permalink( 'destinationpostid' ) ) ;
exit;
}
You would need to pass the correct parameter to get_permalink() depending on where you want to redirect the users.
Thread Starter
Pete
(@perthmetro)
Thanks so much for that… sorry for my ignorance when it comes to php, but let’s say I want redirect to http://www.xyz.com/abc
how would I use that snippet?
Thread Starter
Pete
(@perthmetro)
Ahhh i get it now like this?
if ( 0 == count_user_posts( get_current_user_id() ) ) {
wp_redirect( get_permalink( 34 ) ) ;
exit;
}
if the page ID was 34?
Does this go in functions.php
?
You can put it in functions.php
if you wrap it in a function like so:
function mysite_redirect_postless_users()
{
if ( 0 == count_user_posts( get_current_user_id() ) ) {
wp_redirect( get_permalink( '34' ) ) ;
exit;
}
}
add_action( 'template_redirect', 'mysite_redirect_postless_users' );
Also note that you will need to wrap the page ID of 34 in single quotes inside of get_permalink, but other than that, you look like you get the idea 🙂 Let me know how that works for you!