0

I have an application with 3 custom post types, A, B, and C. The post types B and C are related to A using acf relationship fields. I've designed a single template for A post types. When viewing this template post meta from A, and B are queried and displayed.

Upon login my users go to a dashboard and choose from a select list one of the A CPT (custom post types). This sets the postID in a session variable of A and they are redirected to A's permalink.

Within the system my users need a way to view various pieces of data from all B and C CPT's so for each of these scenarios i've created a unique page with a custom template one to display all related B post meta, and the other page display's all of the C's post meta.

Each user can have many A custom post types, all having their own unique B and C related post types.

An example is

A.1 B.1,B.1,B.1,B.1,B.1 C.1,C.1,C.1,C.1,C.1

A.2 B.2,B.2,B.2,B.2,B.2, C.2,C.2,C.2,C.2,C.2,

I need some how to create unique URL's so they can bookmark and go directly to the custom page to show all of B.2 CPT's information which relates to A.2 CPT.

Right now when they switch between A CPT's they use a select drop down which clears and resets the session variable storing the A CPT ID. So when they go to the page display B they see the correct related data.

How can I setup pages / posts and unique permalink URL's without parameters so they can view the data. I know I could post ?val=23 to the pages and they could bookmark them but i'd much rather use a permalink structure if possible.

Any suggestions on how to re-structure this?

0

If your only need is convert a a permalink structure in a get variable use an endpoint.

<?php
/**
 * Plugin Name: Question 112350 Plugin
 * Author: G.M.
*/

/**
* Add a new role cloning capabilities from editor and flush rewrite rules
*/
function install_q112350_plugin() {
    plugin_q112350_endpoint();
    flush_rewrite_rules();
}

/**
* Remove the role and flush rewrite rules
*/
function unistall_q112350_plugin() {
    flush_rewrite_rules();
}

/**
* Add the endpoint
*/
function plugin_q112350_endpoint() {
    add_rewrite_endpoint( 'myvar', EP_ALL );
}

add_action( 'init', 'plugin_q112350_endpoint' );
register_activation_hook( __FILE__, 'install_q112350_plugin' );
register_deactivation_hook( __FILE__, 'unistall_q112350_plugin' );

Now the url http://example.com/myvar/125 will set the variable myvar = 125.

You can use get_query_var('myvar'); to retrieve this value in any template file or in pre_get_posts action and in any other later hook.

| improve this answer | |

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.