0

So I came up with this idea. It works like autoresponder, which send already prepared and scheduled content every 7(let's say) days to a all subscribers. And for a new subscriber it starts from the content 1, then later, sends content 2, etc.

I need this on wordpress, except there would be registrations and after registration new member could see only 1st posts. After 7 days, there would be more posts unhidden for him and so on. Another new member couldn't see that new posts, till he would wait for a 7 days.

Do you get the idea? Maybe you can help me out to find a plugin for this if it exists. If it doesn't maybe there are volunteers to create plugin like that? Anyway, I would really appreciate any of your help !

2 Answers 2

0

you can count how many posts user can see like that: (int) ( ( time() - strtotime( get_userdata(get_current_user_id( ))->user_registered ) ) / ( 7 * 24 * 60 * 60 ) ) + 1;

So you add filter for pre_get_posts to show user as many posts as compleate weeks he has spendt on your website.

And to prevent seeing content for custom entered links you add filter to content, where you chack if current post is in avalable posts for current user.

And of course you show all for admins

add_filter( 'pre_get_posts', 'prefix_pre_get_posts' );

function prefix_pre_get_posts( $query ) {
    if( ! is_admin() && 'post' == $query->post_type ) { // is_main_query() ?
        $post_pre_page = null;
        if( is_user_logged_in() && ! current_user_can( 'administrator' ) ) {
            $post_pre_page = (int) ( ( time() - strtotime( get_userdata(get_current_user_id( ))->user_registered ) ) / ( 7 * 24 * 60 * 60 ) ) + 1;
        } elseif( ! is_user_logged_in() ) {
            $post_pre_page = 0;
        }
        if( ! is_null( $post_pre_page ) ) {
            $query->set( 'posts_per_page', $post_pre_page );
            // Show pastest posts first
            $query->set( 'order', 'DESC' );
            $query->set( 'orderby', 'date' );
        }
    }
}

add_filter( 'the_content', 'prefix_filter_the_content' );

function prefix_filter_the_content( $content ) {

    if( current_user_can( 'administrator' ) )
        return $content;
    $current_id = get_the_id();
    $allowed_posts = get_posts( array( 'posts_per_page' => -1 ) );
    $flag = false;
    if( ! empty( $allowed_posts ) )
        foreach( $allowed_posts as $p )
            if( $current_id == $p->ID ){
                $flag = true;
                break;
            }
    if( ! $flag ) {
        return __( 'Your are not able to see these post', 'your-textdomain' );
    }
    return $content;
}

Simply add these code to your functions.php.

PS: to change 7 days to 3 ( for ex ) change it here '( 7 * 24 * 60 * 60 )' to '( 3 * 24 * 60 * 60 )'

2
  • Hi, thank you for your help. This almost could do it, but it just adds random posts. I am looking for specific posts scheduling. Every post should be customized when it shows up for a new member.
    – Simon
    Jan 16, 2015 at 16:15
  • Not shore i understend what u mean by "Every post should be customized when it shows up for a new member.", could u explane it ? "but it just adds random posts" - thats strange.. it should show the pastest posts first ( may be there should be ASC not DESC in my example, but i think i wrote it fine ). Also if you have some extra WP_Query's or get_posts with custom parametrs such as meta_key then it might ruin our logic and we need to reset thows statements in our filter.. Jan 16, 2015 at 17:09
0

Use a post meta field to store a numeric value representing the number of days someone has to have been a member before they can see this specific post.

Use pre_get_posts to check the age of the member and adjust the $query accordingly to include a meta_query that only shows posts with a value less than or equal to the member's age.

I can whip up some pseudo code if needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.