0

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.

2

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!';
}
  • Wow...never heard of this, very very useful hint for furure projects. I always ended up using nested hierarchical posttypes to achieve that kind of permalink structure. – rfrq Jul 2 '13 at 9:24
  • Wow. This is exactly what I was looking for. Can you tell me what is the best way to flush rewrite rules. From what I read at link rewrite rules need to be flushed for permalinks to work. – Praz Jul 2 '13 at 12:16
  • @Praz if this is a plugin, or theme for distribution, the first two examples on flush_rewrite_rules are what you should use. if this is a personal theme, you can simply visit the permalinks settings page in admin and rewrites will be flushed. – Milo Jul 2 '13 at 14:29
  • @Milo One question though. if I print <div><code> <?php global $wp_rewrite; echo '<pre>'; print_r($wp_rewrite->rules); echo '</pre>'; ?> </code></div> in my template file I see that these endpoints are added for all post types. How can I restrict it to only single custom post type(movies in this example) and have a different set of endpoints for my second content type? I am using WP Types plugin for managing custom content types. – Praz Jul 2 '13 at 19:18
  • @Milo When I try this, the addition of the endpoint to the url causes the 404 template to load. Any suggestions? – christian Sep 22 '14 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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