• Hello there,

    mostly i can figure out all kind problems. But this time i going be nuts.

    At the backend i have a template create page and the result is saved in the wp_posts as post_name ‘person’ and post_type ‘family_tree’ and post_name ‘family’ and post_type ‘family_tree’.

    At the front end the templates need to be accessed thru the url:
    mydomain.com/family-tree/person/2/I101/
    mydomain.com/family-tree/family/2/F11/ where example is the tree id and F11 the family id to show.

    I manage to get WP get the right pages at the right time, but now when i try to access the page the parameters are striped from the url and mydomain.com/family-tree/person/ is loaded. Whe i look into chrome developer
    network is see that I101 and F11 give a 301 error.

    This is to code so far.

    add_action('init', 'wp_gena_plugin_rules');
     function wp_gena_plugin_rules() {
      //
    
     // flush_rewrite_rules();
      add_rewrite_rule('^family-tree/person/([0-9]+)/I([0-9]+)/?', 'index.php?pagename=person&post_type=family-tree&pers_id=$matches[2]&tree=$matches[1]', 'top');
      add_rewrite_rule('^family-tree/family/([0-9]+)/F([0-9]+)/?', 'index.php?pagename=family&post_type=family-tree&fam_id=$matches[1]&tree=$matches[2]', 'top');
      flush_rewrite_rules();
     }
      add_filter('query_vars', 'wp_gena_plugin_query_vars');
     function wp_gena_plugin_query_vars($vars) {
      $vars[] = 'pers_id';
      $vars[] = 'fam_id';
      $vars[] = 'post_type';
      $vars[] = 'tree';
      $vars[] = 'pagename';
      return $vars;
     }
    
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
      register_post_type( 'family-tree',
        array(
          'labels' => array(
            'name' => __( 'family-tree' ),
            'singular_name' => __( 'family-tree' )
          ),
          'public' => true,
          'has_archive' => false,
        )
      );
    }

  • The topic ‘add_rewrite_rule and post retrieve’ is closed to new replies.