• We’re attempting to use this to make two interlocking CPTs, which are updated through wp_insert_post() and an API call.

    Community CPT: <%ctax_states%>/<%ctax_cities%>/%postname%
    Design CPT: <%ctax_states%>/<%ctax_cities%>/<%ctax_communities%>/%postname%

    Note that the paths must be very similar for both to follow the existing site structure and SEO.

    It looks like the redirects are forcing us to one page, and a very wrong page at that:

    /fl/vero-beach/vero-lake-estates-32967/wilmington-60.html	/northern-ky/
    /fl/vero-beach/vero-lake-estates-32967/willow-32.html	/northern-ky/
    /fl/vero-beach/vero-lake-estates-32967/sierra.html	/northern-ky/
    /fl/vero-beach/vero-lake-estates-32967/sequoia.html	/northern-ky/
    

    We attempted the hooks to disable redirects, but they disabled all and essentially stopped the plugin from working. Any advice?

    Example Community CPT register_post_type()

    $args = array(
          'label'               => __( 'Community', 'twentythirteen' ),
          'description'         => __( 'Community page templates', 'twentythirteen' ),
          // UI Labels
          'labels'              => array(
            'name'                => _x( 'Community', 'Post Type General Name', 'twentythirteen' ),
            'singular_name'       => _x( 'Community', 'Post Type Singular Name', 'twentythirteen' ),
            'menu_name'           => __( 'Community', 'twentythirteen' ),
            'parent_item_colon'   => __( 'Parent Community', 'twentythirteen' ),
            'all_items'           => __( 'All Communities', 'twentythirteen' ),
            'view_item'           => __( 'View Community', 'twentythirteen' ),
            'add_new_item'        => __( 'Add New Community', 'twentythirteen' ),
            'add_new'             => __( 'Add New', 'twentythirteen' ),
            'edit_item'           => __( 'Edit Community', 'twentythirteen' ),
            'update_item'         => __( 'Update Community', 'twentythirteen' ),
            'search_items'        => __( 'Search Communities', 'twentythirteen' ),
            'not_found'           => __( 'Not Found', 'twentythirteen' ),
            'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
          ),
          // Features this CPT supports in Post Editor
          'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', ),  
          'hierarchical'        => false,
          'public'              => true,
          'show_ui'             => true,
          'show_in_menu'        => true,
          'show_in_nav_menus'   => true,
          'show_in_admin_bar'   => true,
          'menu_position'       => 5,
          'can_export'          => true,
          'has_archive'         => false,
          'menu_icon'           => 'dashicons-admin-multisite',
          'exclude_from_search' => false,
          'publicly_queryable'  => true,
          'capability_type'     => 'post',
          'taxonomies' => array('states', 'cities'),
          // 'rewrite' => false,
          'rewrite' => array('slug' => 'community', 'with_front' => false),
        );
    
        register_post_type( 'community', $args );
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sami Ahmed Siddiqui

    (@sasiddiqui)

    @benjithaimmortal Can you disable the redirect hook only just before wp_insert_post()? I hope the wp_insert_post() works under some condition not globally so it only prevent the new redirect to be created at certain time period.

    
    add_filter( 'permalinks_customizer_auto_created_redirects', '__return_false');
    

    Regards,
    Sami

    Thread Starter Benji Kostenbader

    (@benjithaimmortal)

    Hi Sami,

    Thanks for the quick response!

    We’re running it on a cron, so we can definitely filter the auto-created-redirects there.

    Will report back right away with results

    Thread Starter Benji Kostenbader

    (@benjithaimmortal)

    @sasiddiqui it looks like this happens on the very first install of the plugin. I was wrong to think it was connected to when we fire wp_insert_post().

    We are assigning post_name in the initial wp_insert_post() on these plugins, could that be making part of the error?

    We also assign the taxonomies from there with wp_set_object_terms().

    I can’t think of how either of those very basic functions might hurt the plugin, but I’m not sure? Finally, here’s our taxonomy setup in case it’s the culprit:

    
        $labels = array(
            'name' => _x( 'States', 'taxonomy general name' ),
            'singular_name' => _x( 'State', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search States' ),
            'all_items' => __( 'All States' ),
            'parent_item' => __( 'Parent State' ),
            'parent_item_colon' => __( 'Parent State:' ),
            'edit_item' => __( 'Edit State' ), 
            'update_item' => __( 'Update State' ),
            'add_new_item' => __( 'Add New State' ),
            'new_item_name' => __( 'New State Name' ),
            'menu_name' => __( 'States' ),
        );    
      
        register_taxonomy('states',array('community', 'design'), array(
            'hierarchical' => true,
            'labels' => $labels,
            'show_ui' => true,
            'show_in_rest' => true,
            'show_admin_column' => true,
            'query_var' => false,
            'rewrite' => array( 'slug' => 'state' ),
        ));
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamically Updating CPT Permalinks’ is closed to new replies.