Adding `supports` array to WordPress custom post type

Use ‘supports’ => [ ‘title’, ‘editor’, ‘thumbnail’ ] – different values, not keys. If we look into register_post_type(), we find these lines: if ( ! empty( $args->supports ) ) { add_post_type_support( $post_type, $args->supports ); unset( $args->supports ); } elseif ( false !== $args->supports ) { // Add default features add_post_type_support( $post_type, array( ‘title’, ‘editor’ ) … Read more

Is it possible to place custom post type files inside a folder in theme directory?

You may want to look at the TwentySixteen theme, which does it this way: In single.php: get_template_part( ‘template-parts/content’, ‘single’ ); Several templates are grouped in the ‘template-parts’ folder. You could use a similar logic for your custom post type. It seems that the technique comes from _underscores.

How to quickly reorder posts in the admin panel that will persist for the wp-api

Let’s assume it stores the custom order into the menu_order column in the wp_posts table. If you mean the hierarchical page post type (supports page-attributes) then one can order with the query variables: /wp-json/wp/v2/pages/?orderby=menu_order&order=asc If you mean the post post type with: /wp-json/wp/v2/posts/ there’s a way using the rest_{post_type}_query filter: /** * Set orderby to … Read more

How to Duplicate (multiple meta box)?

You didn’t add the save meta action for the facebook meta box. <?php /* Fire our meta box setup function on the post editor screen. */ add_action( ‘load-post.php’, ‘sw_post_meta_boxes_setup’ ); add_action( ‘load-post-new.php’, ‘sw_post_meta_boxes_setup’ ); /* Meta box setup function. */ function sw_post_meta_boxes_setup() { /* Add meta boxes on the ‘add_meta_boxes’ hook. */ add_action( ‘add_meta_boxes’, ‘sw_add_post_meta_boxes’ … Read more

Copy custom field value to post title

Okay! Finally, I was able to make it work. Below is the complete working code. add_filter( ‘wp_insert_post_data’ , ‘modify_post_title’ , ’99’, 2 ); // Grabs the inserted post data so you can modify it. function modify_post_title( $data ) { if($data[‘post_type’] == ‘artist’ && isset($_POST[‘acf’][‘field_573676a95d920’])) { // If the actual field name of the rating date … Read more

Add/Remove current_page_parent class

Replace news with your custom post type and menu-item-000 with the menu item you want to highlight. function wpdev_nav_classes($classes) { // Remove “current_page_parent” class $classes = array_diff( $classes, array( ‘current_page_parent’ ) ); // If this is the “news” custom post type, highlight the correct menu item if ( in_array(‘menu-item-000’, $classes) && get_post_type() === ‘news’ ) … Read more