Coder Social home page Coder Social logo

Post Type not registering about lumberjack HOT 6 CLOSED

rareloop avatar rareloop commented on May 26, 2024
Post Type not registering

from lumberjack.

Comments (6)

adamtomat avatar adamtomat commented on May 26, 2024

Would you mind sharing your PostType class and your config/posttypes.php file with us please?

We can take a look for you @lmartins

from lumberjack.

lmartins avatar lmartins commented on May 26, 2024

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!

from lumberjack.

adamtomat avatar adamtomat commented on May 26, 2024

@lmartins Thanks, I am able to replicate the issue locally. Will have a look at what's causing it 👍

from lumberjack.

adamtomat avatar adamtomat commented on May 26, 2024

@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,
    ];
  }
}

from lumberjack.

lmartins avatar lmartins commented on May 26, 2024

Awesome, thanks so much for the feedback @adamtomat !

from lumberjack.

adamtomat avatar adamtomat commented on May 26, 2024

Fixed the documentation.

from lumberjack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.