Archived topic
GP Blocks / Query loop / custom post type
7 replies · Started by Jan on July 16, 2022
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
Hi there,
you need to make sure the CPT supports the Rest API for it to display in the editor:
ie. in your CPT args it should include 'show_in_rest' => true,
Hi David,
this did the trick ;-).
Thanks for this helping hand! I greatly appreciate that.
Best,
Jan
You're welcome
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 !
Hi there,
i believe you also need to set: 'publicly_queryable' => true,
Hi David,
Thanks for the quick fix, it works !
Glad to hear that!