Need to display same custom post type on 2 different singles templates

To display different templates for the same post type I would make 2 different links, check on which link I’m currently on and decide which template to load. Working example: /** * Register event post type * * Registering event post type will add such a permalink structure event/([^/]+)/?$ */ function wpse_288345_register_event_post_type() { $labels = … Read more

rewrite custom post type slug in wp admin

So what I did was: First make a function that would be returning these slugs based on custom post type name, and if the provided custom slug didn’t meet the requirements it falls back to a default value: function my_get_custom_slugs($cpt){ $all_the_slugs = [ “ugly_machine_name_1” => “default-pretty-name-1”, “ugly_machine_name_2” => “default-pretty-name-2”, //…etc ]; $r_val = array(); $options … Read more

Shortcode insertion in tab

Sounds like you need to wrap your shortcode contents in ob_start()and return ob_get_clean() require_once(dirname(__FILE__).’/post-type.php’); //file that registers CPT function wporg_shortcodes_init(){ function wporg_shortcode($atts = []) { extract( shortcode_atts( array( ‘term’ => ‘columns’ ), $atts ) ); $custom_taxonomy = $atts[‘term’]; ob_start(); // <- works like magic // add query of custom post type board_members $recentPosts = new … Read more

Add category in post type dynamically

You need to register the custom post type with support for the category taxonomy: add_action(‘init’, ‘cyb_register_post_type’); function cyb_register_post_type() { $args = array( // All the other args ‘taxonomies’ => array( ‘category’ ), ); register_post_type( ‘my_post_type’, $args ); } Then you can set relationships between the custom post type and the categoy taxonomy as you was … Read more