[wp-trac] [WordPress Trac] #49309: Permalinks not working properly for Custom Post Types and Multisite

WordPress Trac noreply at wordpress.org
Tue Jan 28 11:42:22 UTC 2020


#49309: Permalinks not working properly for Custom Post Types and Multisite
--------------------------+-----------------------------
 Reporter:  Klian         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Permalinks    |    Version:  5.3
 Severity:  normal        |   Keywords:
  Focuses:  multisite     |
--------------------------+-----------------------------
 I have a WP Multisite with some custom post types, one of them:

 {{{#!php
 <?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
 <?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

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49309>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list