Disable block from editor based on post type

I’ve made a Gutenberg block which is only appropriate to show on hierarchical post types, so I want to disable it from the block inserter for non-hierarchical post types. I thought about how to achieve this in PHP, but the WordPress documentation on registering blocks seems to suggest that blocks should be registered in PHP … Read more

How to get attachments for a specific post type?

I have this page where I am showing all post’s attachments. This is the code: <?php $args = array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘published’, ‘posts_per_page’ =>25, ‘post_parent’ => null, // Post-> ID; ‘numberposts’ => null, ); $attachments = get_posts($args); $post_count = count ($attachments); if ($attachments) { foreach ($attachments as $attachment) { echo “<div class=\”post … Read more

Exclude top-level pages from search results

With the following code I can exclude all posts and pages that are top-level, but I would like to apply this only to pages, not to posts (but I still want all posts in the results): function search_filter( $query ) { if( $query->is_search AND $query->is_main_query() ) { $query->set( ‘post_parent__not_in’, array( 0 ) ); $query->set( ‘post_type’, … Read more

Overwrite rewrite-slug of built in post-type ‘post’

I need to change the rewrite-slug of the built in post-type ‘post’ to ‘example.com/magazine/news/any-nice-news-item’. When I re-register the post-type ‘post’ and set the rewrite-slug to ‘magazine/news’ it works fine. But now I’m not sure about any side-effects. Does anybody have any positive or negative experience with that? Here is the code: register_post_type( ‘post’, array( ‘labels’ … Read more