• In wordpress I have /%category%/%postname%/ as my custom structure under permalinks

    I installed sublanguage and set my wprentals listings post type to enable translations

    Where before my listings showed under holiday-home/barbados/villa/[the property], in the subpanel settings it said that holiday-home was replaced by estate_property (which I think was the default)

    but then my property showed under estate_property/[the property] with no categories

    So I figured I’d deactivate sublanguage to get back the previous behavior but the property is still now at estate_property/[the property]

    Please advise 1) how to get the categories in the structure 2) how to make sure that if subpanel is deactivated that things still work as before.

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter plushvilla

    (@plushvilla)

    In wordpress Settings->Permalink Settings for Custom Post Types

    I have
    estate_property
    https://sapphire.dreamhosters.com/holiday-home/%property_category%/%postname%/

    So that should have been reflected in the sublanguage rename plus right now with or without the sublanguage plugin activated the link listed here does not work.

    Plugin Author maximeschoeni

    (@maximeschoeni)

    First deactivate sublanguage and rebuild permalinks (just go to settings>permalinks and click save).

    If you did that and it doesn’t work, delete the .htaccess file in the root of the WP installation and try again (have a backup first).

    If still no luck, deactivate all other plugin and set a default theme (twenty-x) and rebuild permalinks. Then reactivate everything.

    Thread Starter plushvilla

    (@plushvilla)

    Ok.. rebuilding permalinks seemed to work… .htaccess was actually empty fyi.

    But now we’ve got that figured out how do I get the desired behaviour with the categories in the uri?

    Thread Starter plushvilla

    (@plushvilla)

    My apologies… the permalink section was enabled by Custom Post Type Permalinks plugin so it’s likely not your issue why the categories specified in that plugin don’t show up.

    I would still like the categories but I guess I’m going to have to figure out how I would get that functionality. Any ideas would be greatly appreciated because for now it seems i have to choose bewteen the directory structure I want and translations

    • This reply was modified 2 years, 11 months ago by plushvilla.
    Thread Starter plushvilla

    (@plushvilla)

    Plugin Author maximeschoeni

    (@maximeschoeni)

    The reason why it is complicated with permalink is because WordPress translate the post-type and taxonomy slugs using the admin user language. Of course on a multilanguage site this language doesn’t correspond to the language of the user on the front end, so the plugin needs to overwrite this translation with the actual post-type (or taxonomy) slug.

    Lets have an example. Suppose our site use a custom post type “book”. This post type is registered somewhere in the theme files (or in another plugin):

    
    register_post_type( 'book', array(
        'public'             => true,
        'rewrite'            => array( 'slug' => __('book', 'my-domain') ),
        '...' => '...'
    );
    

    As we see, the post-type slug is defined in the language .mo/.po files, using the backend user language. So when a frontend user request a permalink using a translation of “book”, we cannot find back from what post-type it corresponds (because .mo/.po files just translates in one way). So instead we have to replace the slug by something that is defined somewhere we can access from the front-end. That’s why Sublangage provides an interface for overriding post-type (and taxonomies) slugs.

    So now, back in your situation, when you’re using a taxonomy (“property_category”) slug inside a post-type permalink, I think the taxonomy slug will not be handled (it would if it was in a taxonomy permalink but this is actually a post-type permalink). I think the only way to deal with it is to remove the taxonomy slug translations (in the .mo/.po files) or to set it exactly as the post-type name (the first parameter of register_taxonomy function), in every languages. Of course this will prevent the category slug to be translated in the pages/posts/custom post-type permalinks.

    I wrote a more in depth follow up here: https://github.com/maximeschoeni/sublanguage/issues/60

    Given an expected example
    https://myhost.com/?holiday-home/barbados/villa/sapphire-beach/

    where I would want https://myhost.com/?sublanguage_slug=/ru/&property_category=barbados/villa&estate_property=sapphire-beach/

    I’m not clear what the problem would be.. Let’s say holiday-home was replaced with estate_property as the plugin does… I think I can change it back to holiday-home right?

    And then the only problem is the barbados and villa which are hierarchical categories but since each language is spit into a separate post it too can have a separate hierchy right which could either be translated matching items or the very same barbados/villa if you didn’t want to translate. Isn’t that correct?

    Wrt your great above explanation.

    1) So when a frontend user request a permalink using a translation of “book”, we cannot find back from what post-type it corresponds

    So this is understandable in that you need to have a mapping between the initial slug and the post type which you do already have in sublanguage

    2) Wrt handling the property_category another way to handle it would be to simply wildcard that portion and ignore it in the retrieval of the property type. i.e: it’s just cosmetic and actually serves no purpose but the page is still retrieved where currently it isn’t. Wouldn’t that work?

    But again I’m not sure why if they categories actually match in the corresponding post (which is an entirely different post for the other language) why it would be an issue.

    • This reply was modified 2 years, 11 months ago by garpinc.
    • This reply was modified 2 years, 11 months ago by garpinc.

    FYI here is where the type was registered in code if it helps

    <?php
    // register the custom post type
    add_action('setup_theme', 'wpestate_create_property_type',20);
    
    if( !function_exists('wpestate_create_property_type') ):
    function wpestate_create_property_type() {
        $rewrites   =   wpestate_safe_rewite();
        if(isset($rewrites[0])){
            $slug=$rewrites[0];
        }else{
            $slug='properties';
        }
        register_post_type('estate_property', array(
            'labels' => array(
                'name'                  => esc_html__( 'Listings','wprentals-core'),
                'singular_name'         => esc_html__( 'Listing','wprentals-core'),
                'add_new'               => esc_html__( 'Add New Listing','wprentals-
    core'),
                'add_new_item'          => esc_html__( 'Add Listing','wprentals-core
    '),
                'edit'                  => esc_html__( 'Edit','wprentals-core'),
                'edit_item'             => esc_html__( 'Edit Listings','wprentals-co
    re'),
                'new_item'              => esc_html__( 'New Listing','wprentals-core
    '),
                'view'                  => esc_html__( 'View','wprentals-core'),
                'view_item'             => esc_html__( 'View Listings','wprentals-co
    re'),
                'search_items'          => esc_html__( 'Search Listings','wprentals-
    core'),
                'not_found'             => esc_html__( 'No Listings found','wprental
    s-core'),
                'not_found_in_trash'    => esc_html__( 'No Listings found in Trash','wprentals-core'),
                'parent'                => esc_html__( 'Parent Listings','wprentals-core')
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => $slug),
            'supports' => array('title', 'editor', 'thumbnail', 'comments','excerpt'),
            'can_export' => true,
            'register_meta_box_cb' => 'wpestate_add_property_metaboxes',
            'menu_icon'=>WPESTATE_PLUGIN_DIR_URL.'/img/properties.png'
             )
        );

    with

    if( !function_exists('wpestate_safe_rewite') ):
    function wpestate_safe_rewite(){
        $rewrites   =   get_option('wp_estate_url_rewrites',true);
        $return     =   array();
    
        if(is_array($rewrites)){
            foreach($rewrites as $key=>$value){
                $return[$key] = str_replace('/', '', $value);
            }
        }
    
        return $return;
    
    }
    endif;
    • This reply was modified 2 years, 11 months ago by garpinc.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Category does not show in url’ is closed to new replies.