Dynamically append custom post type to end of url

Here is something I came up with to solve this exact problem. add_action(‘wp_list_categories’,’example_wp_list_categories’); function example_wp_list_categories($output) { global $post; foreach (get_categories() as $cat) { if (preg_match(“/\/category\/$cat->slug\//”, $output)) { $output = str_replace(‘/category/’ . $cat->slug . “https://wordpress.stackexchange.com/”, ‘/category/’ . $cat->slug . ‘/?post_type=” . $post->post_type, $output); } } return $output; } Regex isn”t a strong point of mine, so … Read more

Custom post type permalink structure

function myrules(){ add_rewrite_rule(‘^yourcptslughere/([^/]*)/([^/]*)/([^/]*)/?’,’index.php?p=$matches[1]&taxonomy=$matches[2]&name=$matches[3]’,’top’); } add_action(‘init’,’myrules’); Replace the ‘yourcptslughere‘ with what you wanted, and then add that to functions.php then flush your rewrite rules, and the final example you posted should work. I doubt it will be what the_permalink() returns however so you will have to construct the urls yourself, however they should be viewable at … Read more

help with rewrite_tag and rewrite_rule for custom page GET variables [duplicate]

You should use get_query_var rather than $_GET. But you will need to register you custom variables, for instance: add_filter(‘query_vars’, ‘register_my_query_vars’ ); function register_my_query_vars( $qvars ){ //Add these query variables $qvars[] = ‘video_id’; $qvars[] = ‘vide_title’; $qvars[] = ‘venue_src’; return $qvars; } Then you should be able to use get_query_var(‘venue_id’).

WordPress custom permalinks, pages are now 404

You need to setup your permalinks for menutype using custom rewrite rules. What you’ve done is apply the menutype prefix to everything, even though menutype isn’t relevant to everything, so things are being misinterpreted. You would need something similar to this: function custom_rewrite( $wp_rewrite ) { $feed_rules = array( ‘([^/]+)(/[0-9]+)?/?$’ => ‘index.php?menu_type=”. $wp_rewrite->preg_index(1).”&post_name=”. $wp_rewrite->preg_index(2) ); … Read more

How to use permalink query to go to specific tabs in posts

I’ve found out the solutions, though not perfect, but it gets the job done. Following is the code add_action(‘init’, ‘my_init’); function project_ace2_init() { global $wp; $wp->add_query_var(‘tab’); // Needed so get_query_var(‘tab’) will work add_rewrite_rule( //'(.+?)/([^/]+)(/([^/]+))?/?$’, //Original : ‘(.+?)/([^/]+)(/[0-9]+)?/?$’ ‘((?:(?!page|tag|category|author|search|feed|type))[^/]+)/([^/]+)(/([^/]+))?/?$’ ‘index.php?category_name=$matches[1]&name=$matches[2]&tab=$matches[4]’, ‘top’ ); } The rule is taken from the default WordPress rules for permalink as /%category%/%postname%/, … Read more