0

I need an advice on how to the following: I have registered course custom post type and created one for example Course1. Course1 has child posts - some are private (e.g Lectures) and some are not.

When user tries to open Lectures user's meta field is checked and based on the value the content is displayed or the user is redirected to the parent. I have used template_redirect hook (might not be the right one). What I need now is to show some banner with notification (for example you cant see private content) on parent course post after redirection. How can I know that user has tried to open Lectures and it was redirected? I tried using session in redirect function but didnt make it (the banner was active on all Course1 post). Could you please give me some advice? Thank you.

1 Answer 1

0

You can use wp_get_referer function to acheive your requirement.

Below is the useful code snippet for you.

    function wdm_referer()
    {
        global $post;

        if( post type is child  ) {

            $child_post_id = $post->ID;

            $parent_id = get_parent_course_id($child_post_id); // your custom function to get parent course id

            if( parent task is not completed ) { // a condition that you are checking on child page and redirecting

                // to get http referer
                $page_referer = wp_get_referer();

                // to get parent post permalink
                $parent_permalink = get_permalink( $parent_id );

                // if parent course link is same as http referer
                if( $page_referer == $parent_permalink ) {
                    //user came from parent course. Your code to display in content
                }
            }
        }
    }

add_action('the_content', 'wdm_referer');
1
  • Thank you so much. I will check this out once I come back from work. :) Where parent task is not completed I should check whether user can see child content, right?
    – scarably
    Commented Jun 18, 2015 at 10:17

Your Answer

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

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