My requirement is exactly similar to Tabbed Post.

I have Advanced Custom Fields (ACF) plugin to store data.

So pulling up the requirement from the wordpress support thread:

Movie Summary | Synopsis | Screens | Trailer | Comments | Add your Review

Movie summary is the_content(), Synopsis is the_excerpt(), Screens and Trailers are custom field values.

I want to know how I can split the content i.e. Summary, Synopsis, Screens, Trailers into Tabs which will reload the page. I do not want to change the tabs using javascript and specifically want to reload page every time.

A working example would be: Example

Thanks in advance.

1 Answer
1

You can use rewrite endpoints to achieve this.

First, register your endpoints:

function wpa_movie_endpoints() {
    add_rewrite_endpoint( 'synopsis', EP_PERMALINK );
    add_rewrite_endpoint( 'screens', EP_PERMALINK );
    add_rewrite_endpoint( 'trailer', EP_PERMALINK );
}
add_action( 'init', 'wpa_movie_endpoints' );

So now in addition to http://domain.com/post-name/ (or whatever your particular permalink structure is), you’ll have:

http://domain.com/post-name/synopsis/
http://domain.com/post-name/screens/
http://domain.com/post-name/trailer/

You can then check for the existence of these query vars in a template action, or in the template itself, and show the appropriate content:

global $wp_query; // may be necessary, depending on where you're using this
if( array_key_exists( 'synopsis', $wp_query->query_vars ) ){
    echo 'show synopsis!';
}

Leave a Reply

Your email address will not be published. Required fields are marked *