• Resolved erikstainsby

    (@erikstainsby)


    I have created a custom_post_type which is in essence a clone of Pages post type. It appears properly in the admin context; I can edit, assign parent, and order the posts. They appear in their own meta box in the Theme > Menus admin page; I can add them to the hierarchy, sort, nest and save the menu. All is good and as expected when I come back to these admin context pages.

    These new post type items however are not being returned to the templates. They do not show up in the theme’s nav menu. I have set the menu’s Theme Location. The ordinary page type posts do get rendered.

    What do I need to modify in the theme-rendering chain to add my custom post type menu items to the rendered nav menu hierarchy?

    ~ Erik

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter erikstainsby

    (@erikstainsby)

    Do I need to write a custom nav menu walker to encompass my custom post type objects ?

    Thread Starter erikstainsby

    (@erikstainsby)

    A snap of the Themes > Menus page: https://imgur.com/e3KuVTi

    Thread Starter erikstainsby

    (@erikstainsby)

    Here’s the entire plugin as it currently stands.

    defined( 'ABSPATH' ) OR exit;
    
    register_activation_hook( __FILE__, array('Fixtures','activation_handler'));
    register_deactivation_hook( __FILE__, array('Fixtures','deactivation_handler')); 
    
    add_action('plugins_loaded',array('Fixtures','init'));
    
    class Fixtures {
    	protected static $instance;
    	public static function init() {
    		is_null( self::$instance ) AND self::$instance = new self;
                    return self::$instance;
    	}
    
    	public function __construct() {
    		$this->plugin_url = plugins_url().'/fixtures';
    		if( is_admin() ) {
    			add_action( 'init', array( $this,'create_post_type'));
    		}
    	}
    
    	public static function activation_handler() {
    		global $wp_roles;
    		$wp_roles->add_cap('administrator', 'manage_fixtures');
    		flush_rewrite_rules();
    	}
    
    	public static function deactivation_handler() {
    		global $wp_roles;
    		$wp_roles->remove_cap('administrator', 'manage_fixtures');
    		flush_rewrite_rules();
    	}
    
    	function create_post_type() {
    		error_log(__FUNCTION__ );
    		$labels = array(
    		    'name' => 'Fixtures',
    		    'singular_name' => 'Fixture',
    		    'add_new' => 'Add New',
    		    'all_items' => 'All Fixtures',
    		    'add_new_item' => 'Add New Fixture',
    		    'edit_item' => 'Edit Fixture',
    		    'new_item' => 'New Fixture',
    		    'view_item' => 'View Fixture',
    		    'search_items' => 'Search Fixtures',
    		    'not_found' =>  'No Fixtures found',
    		    'not_found_in_trash' => 'No Fixtures found in trash',
    		    'parent_item_colon' => 'Parent Fixture:',
    		    'menu_name' => 'Fixtures'
    		);
    		$args = array(
    			'labels' => $labels,
    			'description' => "Custom page post-type which restricts title edit & post delete",
    			'public' => true,
    			'exclude_from_search' => false,
    			'publicly_queryable' => true,
    			'show_ui' => true,
    			'show_in_nav_menus' => true,
    			'show_in_menu' => true,
    			'show_in_admin_bar' => true,
    			'menu_position' => 15,
    			'menu_icon' => '/wp-content/plugins/fixtures/img/padlock.png',
    			'capability_type' => 'page',
    			'hierarchical' => true,
    			'supports' => array('title','editor','page-attributes'),
    			'has_archive' => true,
    			'rewrite' => array('slug' => 'fixture'),
    			'query_var' => true,
    			'can_export' => true
    		);
    		register_post_type('fixture',$args);
    	}
    }
    Thread Starter erikstainsby

    (@erikstainsby)

    Removing the
    if( is_admin() ) {
    condition from around the add_action('init',...
    did the trick.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom post type not rendered into frontside nav menus’ is closed to new replies.