Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#49309 closed defect (bug) (duplicate)

Permalinks not working properly for Custom Post Types and Multisite

Reported by: klian's profile Klian Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.3
Component: Permalinks Keywords:
Focuses: multisite Cc:

Description

I have a WP Multisite with some custom post types, one of them:

<?php
$labels = array(
                'name'               => _x( 'Alimentos', 'post type general name', 'mydomain' ),
                'singular_name'      => _x( 'Alimento', 'post type singular name', 'mydomain' ),
                'menu_name'          => _x( 'Alimentos', 'admin menu', 'mydomain' ),
                'name_admin_bar'     => _x( 'Alimentos', 'add new on admin bar', 'mydomain' ),
                'add_new'            => _x( 'Añadir nuevo', 'Alimento', 'mydomain' ),
                'add_new_item'       => __( 'Añadir nuevo Alimentos', 'mydomain' ),
                'new_item'           => __( 'Nuevo Alimentos', 'mydomain' ),
                'edit_item'          => __( 'Editar Alimentos', 'mydomain' ),
                'view_item'          => __( 'Ver Alimentos', 'mydomain' ),
                'all_items'          => __( 'Todas las Alimentos', 'mydomain' ),
                'search_items'       => __( 'Buscar Alimentos', 'mydomain' ),
                'parent_item_colon'  => __( 'Alimentos padres:', 'mydomain' ),
                'not_found'          => __( 'No se han encontrado Alimentos.', 'mydomain' ),
                'not_found_in_trash' => __( 'No se han encontrado Alimentos en la papelera.', 'mydomain' )
        );

        $args = array(
                'labels'             => $labels,
                'description'        => __( 'Description.', 'mydomain' ),
                'public'             => true,
                'publicly_queryable' => true,
                'show_ui'            => true,
                'show_in_menu'       => true,
                'query_var'          => true,
                'capability_type'    => 'post',
                'has_archive'        => false,
                'hierarchical'       => false,
                'menu_position'      => null,
                'supports'           => array( 'title', 'thumbnail', 'page-attributes' ),
                'rewrite' => array(
                        'with_front' => false
                )
        );

        register_post_type( 'alimento', $args );

I'm using this code to get the permalink in another site for a post with this CPT:

<?php
switch_to_blog(2); 
$post_id = 530;
$permalink = get_permalink($post_id);
echo $permalink;
restore_current_blog();

If I execute this code in single-alimento.php, it returns:

http://localhost/en/alimento

If I execute this code in another template (or a file in root directory using require('wp-load.php') ), it works:

http://localhost/en/alimento/my-translated-cpt/

Is it a bug ? Or I'm doing anything wrong ?

Thanks

Change History (1)

#1 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #20861.

Note: See TracTickets for help on using tickets.