[Resolved] GP Blocks / Query loop / custom post type

Home Forums Support [Resolved] GP Blocks / Query loop / custom post type

Home Forums Support GP Blocks / Query loop / custom post type

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2284314
    Jan

    Hi David,

    we created a custom post type and embedded the post type via a custom plugin.

    Now would like to embed a query loop that picks the 3 latest items from the custom post type. Unfortunately, I don’t get to choose the custom post type from the blocks settings.

    Any idea on what I may be missing?

    Thanks,
    Jan

    #2284342
    David
    Staff
    Customer Support

    Hi there,

    you need to make sure the CPT supports the Rest API for it to display in the editor:

    https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/

    ie. in your CPT args it should include 'show_in_rest' => true,

    #2284569
    Jan

    Hi David,

    this did the trick ;-).

    Thanks for this helping hand! I greatly appreciate that.

    Best,
    Jan

    #2285099
    David
    Staff
    Customer Support

    You’re welcome

    #2492461
    Thierry

    Hi David,

    Sorry for reopening this, but I’ve set up my CPT with show_in_rest => true, still it doesn’t show in the “Select post type” dropdown.

    Here’s how I registered the post type :

    $labels = array(
        'name'                => __( 'Occasions', TEXT_DOMAIN ),
        'singular_name'       => __( 'Occasion', TEXT_DOMAIN )
    );
      
    $args = array(
        'label'               => __( 'Occasions', TEXT_DOMAIN ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'thumbnail' ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 35,
        'menu_icon'           => 'dashicons-hammer',
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => false,
        'capability_type'     => 'post',
        'show_in_rest'        => true,
    
    );
      
    register_post_type( 'occasions', $args );

    I tried flushing_rewrite_rules via code and refreshing the page, but it doesn’t work. Maybe there’s another setting here preventing my CPT from showing ?

    Thanks !

    #2492630
    David
    Staff
    Customer Support

    Hi there,

    i believe you also need to set: 'publicly_queryable' => true,

    #2492717
    Thierry

    Hi David,

    Thanks for the quick fix, it works !

    #2493091
    David
    Staff
    Customer Support

    Glad to hear that!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.