themosis / framework

The Themosis framework core.
https://framework.themosis.com/
GNU General Public License v2.0
671 stars 121 forks source link

Route not found for custom post type only when published #334

Closed bgatellier closed 8 years ago

bgatellier commented 8 years ago

Hi,

I just installed the latest version at this time (1.2.3). Then I created a custom post type following the bookstore example. I am facing a strange problem were the route is found only with previews, but not if the post type is published. Here are my codes:

admin/books.php

<?php

$books = PostType::make('books', 'Books', 'Book')->set([
    'public' => true,
    'rewrite'   => array(
        'slug'      => 'books'
    ),
]);

Metabox::make('Chapitres', $books->getSlug())->set([
    Field::text('author', ['title' => 'Auteur']),
    Field::infinite('chapters', [
        Field::number('number', ['title' => 'Numéro']),
        Field::text('title', ['title' => 'Titre']),
    ], ['title' => 'Chapitres'])
]);

controllers/BooksController.php:

<?php

use Themosis\Facades\View;

class BooksController extends BaseController
{
    public function archive()
    {
        return View::make('books.archive');
    }

    /**
     * Render the single book request page.
     *
     * @param \WP_Post $post
     * @return mixed
     */
    public function single(WP_Post $post)
    {
        return View::make('books.single');
    }
}

routes.php:

<?php

/**
 * Define your routes and which views to display
 * depending of the query.
 *
 * Based on WordPress conditional tags from the WordPress Codex
 * http://codex.wordpress.org/Conditional_Tags
 *
 */
Route::get('page', 'PageController@index');

Route::get('postTypeArchive', ['books', 'uses' => 'BooksController@archive']);
Route::get('singular', ['books', 'uses' => 'BooksController@single']);
jlambe commented 8 years ago

Strange. In your custom post type code you've setup your own slug (which is the same as the default) but as you added it, you have to update the rewrite rules. Try to update the permalinks and let me know how it goes.

bgatellier commented 8 years ago

Oh damn! I forgot that point... Sorry for the duplicate issue (I saw them but I should have done a bad manipulation last time I tried). Now everything works as expected.

I'm coming from Symfony, and Themosis is the way I discover Wordpress so I still have to update my knowledge ;-)

Thanks for the fix and for the framework.

jlambe commented 8 years ago

No problem. Glad your issue is solved.