Closed lmartins closed 6 years ago
Would you mind sharing your PostType class and your config/posttypes.php
file with us please?
We can take a look for you @lmartins
Absolutely @adamtomat ,
Btw, code is straight from the documentation:
config/posttypes.php
:
<?php
return [
/**
* List all the sub-classes of Rareloop\Lumberjack\Post in your app that you wish to
* automatically register with WordPress as part of the bootstrap process.
*/
'register' => [
App\PostTypes\Product::class,
],
];
app\PostTypes\Product.php
:
<?php
namespace App\PostTypes;
use Rareloop\Lumberjack\Post;
use Rareloop\Lumberjack\QueryBuilder\Post as QueryBuilderPost;
class Product extends Post
{
/**
* Return the key used to register the post type with WordPress
* First parameter of the `register_post_type` function:
* https://codex.wordpress.org/Function_Reference/register_post_type
*
* @return string
*/
public static function getPostType()
{
return 'products';
}
/**
* Return the config to use to register the post type with WordPress
* Second parameter of the `register_post_type` function:
* https://codex.wordpress.org/Function_Reference/register_post_type
*
* @return array|null
*/
protected static function getPostTypeConfig()
{
return [
'labels' => [
'name' => __('Products'),
'singular_name' => __('Product'),
'add_new_item' => __('Add New Product'),
],
];
}
}
Thank you!
@lmartins Thanks, I am able to replicate the issue locally. Will have a look at what's causing it 👍
@lmartins Looks like it's just an issue with documentation again. Your post type has been registered successfully, it's just not public. That's because register_post_type
apparently sets public
to false
by default: https://codex.wordpress.org/Function_Reference/register_post_type#public
Also, the following line should be removed (unless you're using the Query Builder):
use Rareloop\Lumberjack\QueryBuilder\Post as QueryBuilderPost;
I'll update the docs at some point today. Your final Post Type class should look like this:
<?php
namespace App\PostTypes;
use Rareloop\Lumberjack\Post;
class Product extends Post
{
/**
* Return the key used to register the post type with WordPress
* First parameter of the `register_post_type` function:
* https://codex.wordpress.org/Function_Reference/register_post_type
*
* @return string
*/
public static function getPostType()
{
return 'products';
}
/**
* Return the config to use to register the post type with WordPress
* Second parameter of the `register_post_type` function:
* https://codex.wordpress.org/Function_Reference/register_post_type
*
* @return array|null
*/
protected static function getPostTypeConfig()
{
return [
'labels' => [
'name' => __('Products'),
'singular_name' => __('Product'),
'add_new_item' => __('Add New Product'),
],
'public' => true,
];
}
}
Awesome, thanks so much for the feedback @adamtomat !
Fixed the documentation.
What are the steps to reproduce this issue?
I'm basically following the steps described on the new documentation for a Bedrock environment, and got stuck in the part where we register a new post type.
I've added the
Product
class exactly as described in the docs, with the two required methods, and proceeded to register the class inconfig\posttypes.php
.I've confirmed the Products class is called during the application runtime, but still no product post type available in the admin.
I'm probably missing something, wondering if you could point me help understand what.
What versions of software are you using?
Operating System: OSX
PHP Version: 7.2.5
Lumberjack Version: Core is version 3.2