Create Post tabs in single-{content-type}.php with Custom Field values

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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!';
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x