How to get the parent of a non-hierarchical custom post type being edited in Gutenberg

You are already using the correct Gutenberg/JS code, but it’s a limitation in the REST API which exposes the parent field only for hierarchical post types like page. But you can force the field to appear in the REST API responses via register_rest_field() — example for a my_cpt post type: register_rest_field( ‘my_cpt’, ‘parent’, array( ‘schema’ … Read more

Custom post type permalink returns bad url

get_permalink() (which is used by get_the_permalink() and the_permalink()) returns the “ugly” URL if the post is not published, e.g. draft or scheduled, but you can use the following function instead which temporarily sets the post status to publish so that we’d get the pretty URL. function get_future_permalink( $id ) { if ( $post = get_post( … Read more

How to change post featured image using a custom field of category?

You could filter the the_post_thumbnail() function, which will dynamically show the assigned category image across all your custom post type, rather than using acf_save_post to save the category image in the post featured image meta field. By filtering the the_post_thumbnail() for your specific post type, this means if you change the image on category in … Read more

Combining sorted and random CPT

Try to get two different arrays of posts and loop through array A. Before get post data of A element get random element from array B. For example: $array_a = [‘post_id_a1’, ‘post_id_a2’, ‘post_id_a3’]; $array_b = [‘post_id_b1’, ‘post_id_b2’, ‘post_id_b3’]; foreach ( $array_a as $a_post_id ) { $is_b_should_displayed = mt_rand( 0, 1 ); if ( $is_b_should_displayed && … Read more

Custom Post Type Not working like a Post?

When you declare your “Arrangements” custom post type, be sure to add ‘author’ and ‘breadcrumbs’ as parameters to the “supports” array. For example, it might look something like: $supports = array( ‘title’, ‘author’, ‘breadcrumbs’, ‘editor’, ‘excerpt’, ‘thumbnail’, ‘comments’, ‘custom-fields’, ‘revisions’, ); $labels = array( ‘name’ => ‘Arrangements’, ‘singular_name’ => ‘Arrangement’, ‘menu_name’ => ‘Arrangements admin menu’), … Read more