1

Mates,

I've created a custom post type. Created some posts of that type, but when I try to access to any of them, I get 404 error. Also created single theme (single-pb_progproy.php).

Here's the code...

/*********************************************

    Programas/Proyectos

    *********************************************/
    class PB_ProgProy {
        public function __construct(){
            $this->register_post_type();
            $this->taxonomies();
            //$this->metaboxes();
        }

        public function register_post_type(){
            $labels = array(
                'name'                => __( 'Programas/Proyectos', 'text-domain' ),
                'singular_name'       => __( 'Programa/Proyecto', 'text-domain' ),
                'add_new'             => _x( 'Agregar Programa/Proyecto', 'text-domain', 'text-domain' ),
                'add_new_item'        => __( 'Agregar Programa/Proyecto', 'text-domain' ),
                'edit_item'           => __( 'Editar Programa/Proyecto', 'text-domain' ),
                'new_item'            => __( 'Nuevo Programa/Proyecto', 'text-domain' ),
                'view_item'           => __( 'Ver Programa/Proyecto', 'text-domain' ),
                'search_items'        => __( 'Buscar Programas/Proyectos', 'text-domain' ),
                'not_found'           => __( 'No se encontraron Programas/Proyectos', 'text-domain' ),
                'not_found_in_trash'  => __( 'No se encontraron Programas/Proyectos en la papelera', 'text-domain' ),
                'parent_item_colon'   => __( 'Programa/Proyecto Padre:', 'text-domain' ),
                'menu_name'           => __( 'Prog./Proy.', 'text-domain' ),
                'parent'              => __('Programa/Proyecto Contenedor', 'text-domain'),
            );

            $args = array(
                'labels'              => $labels,
                'hierarchical'        => true,
                'description'         => 'Programas y Proyectos de OLADE',
                'taxonomies'          => array(),
                'public'              => true,
                'show_ui'             => true,
                'show_in_menu'        => true,
                'show_in_admin_bar'   => true,
                'menu_position'       => 25,
                'menu_icon'           => admin_url() . 'images/project.png',
                'show_in_nav_menus'   => true,
                'publicly_queryable'  => true,
                'exclude_from_search' => false,
                'has_archive'         => true,
                'query_var'           => 'progproy',
                'can_export'          => true,
                'rewrite'             => array(
                    'slug' => 'progproy/'
                    ),
                'capability_type'     => 'post',
                'supports'            => array(
                    'title', 'editor','page-attributes'
                    )
            );
            register_post_type('pb_progproy', $args );
        }

        public function taxonomies(){
            $taxonomies = array();

            $taxonomies['tipo'] = array(
                'query_var' => 'tipo_proy',
                'hierarchical' => false,
                'rewrite' => array(
                    'slug' => 'tipo_proy'
                    ),
                'labels' => array(
                    'name'                => __( 'Tipo', 'text-domain' ),
                    'singular_name'       => __( 'Tipo', 'text-domain' ),
                    'add_new'             => _x( 'Agregar Tipo', 'text-domain', 'text-domain' ),
                    'add_new_item'        => __( 'Agregar Tipo', 'text-domain' ),
                    'edit_item'           => __( 'Editar Tipo', 'text-domain' ),
                    'new_item'            => __( 'Nuevo Tipo', 'text-domain' ),
                    'view_item'           => __( 'Ver Tipo', 'text-domain' ),
                    'search_items'        => __( 'Buscar Tipos', 'text-domain' ),
                    'not_found'           => __( 'No se encontraron tipos', 'text-domain' ),
                    'not_found_in_trash'  => __( 'No se encontraron tipos en la papelera', 'text-domain' ),
                    'parent_item_colon'   => __( 'Tipo Padre:', 'text-domain' ),
                    'menu_name'           => __( 'Tipos', 'text-domain' ),
                    ),

                );

            $this->register_all_taxonomies( $taxonomies );
        }

        function register_all_taxonomies( $taxonomies ){
            foreach( $taxonomies as $name => $arr ) {
                register_taxonomy($name, array('pb_progproy') , $arr );
            }
        }


    }

add_action('init', function(){
    new PB_ProgProy();
});

I need friendly urls, so I configured wordpress to work with them. The thing is that when I try to access, let's say...

http://olade.pbertran.dev/progproy/siee/

I get 404 error. I've been searching around, and couldn't find any solution. Tried flush_rewrite_rules right after creating an instance of PB_ProgProy(), but still the same.

Any idea why this isn't working?

thanks in advance!

Pablo

  • 1
    try removing the slash from the rewrite slug. – Milo Dec 5 '14 at 23:04
0

Have you already flushed your WP_Rewrite rules? The easiest way to do that is just re-save your Permalink settings.

  • Already did. And still 404. Any ideas? – Pablo Dec 5 '14 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.